27if (! defined(
'CSRFCHECK_WITH_TOKEN')) {
28 define(
'CSRFCHECK_WITH_TOKEN',
'1');
32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
42$table =
GETPOST(
'table',
'aZ09');
43$action =
GETPOST(
'action',
'aZ09');
50if ($action ==
'convert') {
51 $sql =
"ALTER TABLE ".$db->sanitize($table).
" ENGINE=INNODB";
54if ($action ==
'convertutf8') {
55 $collation =
'utf8_unicode_ci';
56 $defaultcollation = $db->getDefaultCollationDatabase();
57 if (preg_match(
'/general/', $defaultcollation)) {
58 $collation =
'utf8_general_ci';
60 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CHARACTER SET utf8 COLLATE ".$db->sanitize($collation);
61 $resql1 = $db->query($sql);
65 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CONVERT TO CHARACTER SET utf8 COLLATE ".$db->sanitize($collation);
66 $resql2 = $db->query($sql);
72if ($action ==
'convertutf8mb4') {
73 $collation =
'utf8mb4_unicode_ci';
74 $defaultcollation = $db->getDefaultCollationDatabase();
75 if (preg_match(
'/general/', $defaultcollation)) {
76 $collation =
'utf8mb4_general_ci';
78 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CHARACTER SET utf8mb4 COLLATE ".$db->sanitize($collation);
79 $resql1 = $db->query($sql);
83 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CONVERT TO CHARACTER SET utf8mb4 COLLATE ".$db->sanitize($collation);
84 $resql2 = $db->query($sql);
90if ($action ==
'convertdynamic') {
91 $sql =
"ALTER TABLE ".$db->sanitize($table).
" ROW_FORMAT=DYNAMIC;";
100llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-database_tables');
102print
load_fiche_titre($langs->trans(
"Tables").
" ".ucfirst($conf->db->type),
'',
'title_setup');
107if (preg_match(
'/mysql/i', $conf->db->type)) {
108 $sql =
"SHOW TABLE STATUS";
110} elseif ($conf->db->type ==
'pgsql') {
111 $sql =
"SELECT conname, contype FROM pg_constraint;";
113} elseif ($conf->db->type ==
'mssql') {
116} elseif ($conf->db->type ==
'sqlite' || $conf->db->type ==
'sqlite3') {
123 print $langs->trans(
"FeatureNotAvailableWithThisDatabaseDriver");
126 print
'<div class="div-table-responsive-no-min">';
127 print
'<table class="noborder">';
128 print
'<tr class="liste_titre">';
130 print
'<td>'.$langs->trans(
"TableName").
'</td>';
131 print
'<td colspan="2">'.$langs->trans(
"Type").
'</td>';
132 print
'<td>'.$langs->trans(
"Format").
'</td>';
133 print
'<td class="right">'.$langs->trans(
"NbOfRecord").
'</td>';
134 print
'<td class="right">Avg_row_length</td>';
135 print
'<td class="right">Data_length</td>';
136 print
'<td class="right">Max_Data_length</td>';
137 print
'<td class="right">Index_length</td>';
138 print
'<td class="right">Increment</td>';
139 print
'<td class="right">Last check</td>';
140 print
'<td class="right">Collation</td>';
143 $arrayoffilesrich =
dol_dir_list(DOL_DOCUMENT_ROOT.
'/install/mysql/tables/',
'files', 0,
'\.sql$');
144 $arrayoffiles = array();
145 $arrayoftablesautocreated = array();
146 foreach ($arrayoffilesrich as $value) {
148 $shortsqlfilename = preg_replace(
'/\-[a-z]+\./',
'.', $value[
'name']);
149 $arrayoffiles[$value[
'name']] = $shortsqlfilename;
150 if ($value[
'name'] == $shortsqlfilename && ! preg_match(
'/\.key\.sql$/', $value[
'name'])) {
152 $arrayoftablesautocreated[$value[
'name']] = $shortsqlfilename;
157 $sql =
"SHOW TABLE STATUS";
159 $resql = $db->query($sql);
161 $num = $db->num_rows($resql);
164 $obj = $db->fetch_object($resql);
166 print
'<tr class="oddeven">';
168 print
'<td>'.($i+1).
'</td>';
169 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($obj->Name).
'"><a href="dbtable.php?table='.urlencode($obj->Name).
'">'.$obj->Name.
'</a>';
170 $tablename = preg_replace(
'/^'.MAIN_DB_PREFIX.
'/',
'llx_', $obj->Name);
172 if (in_array($tablename.
'.sql', $arrayoffiles)) {
173 if (in_array($tablename.
'.sql', $arrayoftablesautocreated)) {
177 print
img_picto($langs->trans(
"NotAvailableByDefaultEnabledOnModuleActivation"), $img,
'class="small opacitymedium"');
181 print
img_picto($langs->trans(
"ExternalModule"), $img,
'class="small"');
184 print
'<td>'.$obj->Engine.
'</td>';
185 if (isset($obj->Engine) && $obj->Engine ==
"MyISAM") {
186 print
'<td><a class="reposition" href="database-tables.php?action=convert&table='.urlencode($obj->Name).
'&token='.
newToken().
'">'.$langs->trans(
"Convert").
' InnoDb</a></td>';
188 print
'<td> </td>';
191 print $obj->Row_format;
192 if (isset($obj->Row_format) && (in_array($obj->Row_format, array(
"Compact")))) {
193 print
'<br><a class="reposition" href="database-tables.php?action=convertdynamic&table='.urlencode($obj->Name).
'&token='.
newToken().
'">'.$langs->trans(
"Convert").
' Dynamic</a>';
196 print
'<td class="right">'.$obj->Rows.
'</td>';
197 print
'<td class="right">'.$obj->Avg_row_length.
'</td>';
198 print
'<td class="right">'.$obj->Data_length.
'</td>';
199 print
'<td class="right">'.$obj->Max_data_length.
'</td>';
200 print
'<td class="right">'.$obj->Index_length.
'</td>';
201 print
'<td class="right">'.$obj->Auto_increment.
'</td>';
202 print
'<td class="right">'.$obj->Check_time.
'</td>';
203 print
'<td class="right nowraponall">'.$obj->Collation;
205 if (isset($obj->Collation)) {
206 print
'<br><span class="opacitymedium small">'.$langs->trans(
"ConvertInto");
207 if (!in_array($obj->Collation, array(
"utf8_unicode_ci"))) {
208 print
' <a class="reposition" href="database-tables.php?action=convertutf8&table='.urlencode($obj->Name).
'&token='.
newToken().
'">utf8</a>';
210 if (!in_array($obj->Collation, array(
"utf8mb4_unicode_ci"))) {
211 print
' <a class="reposition" href="database-tables.php?action=convertutf8mb4&table='.urlencode($obj->Name).
'&token='.
newToken().
'">utf8mb4</a>';
225 print
'<div class="div-table-responsive-no-min">';
226 print
'<table class="noborder">';
227 print
'<tr class="liste_titre">';
230 print
'<td>'.$langs->trans(
"TableName").
'</td>';
231 print
'<td>Nb of tuples</td>';
232 print
'<td>Nb index fetcher.</td>';
233 print
'<td>Nb tuples insert</td>';
234 print
'<td>Nb tuples modify</td>';
235 print
'<td>Nb tuples delete</td>';
238 $sql =
"SELECT relname, seq_tup_read, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del";
239 $sql .=
" FROM pg_stat_user_tables ORDER BY relname";
241 $resql = $db->query($sql);
243 $num = $db->num_rows($resql);
246 $row = $db->fetch_row($resql);
247 print
'<tr class="oddeven">';
248 print
'<td>'.($i+1).
'</td>';
249 print
'<td>'.$row[0].
'</td>';
250 print
'<td class="right">'.$row[1].
'</td>';
251 print
'<td class="right">'.$row[2].
'</td>';
252 print
'<td class="right">'.$row[3].
'</td>';
253 print
'<td class="right">'.$row[4].
'</td>';
254 print
'<td class="right">'.$row[5].
'</td>';
265 print
'<div class="div-table-responsive-no-min">';
266 print
'<table class="noborder">';
267 print
'<tr class="liste_titre">';
269 print
'<td>'.$langs->trans(
"TableName").
'</td>';
270 print
'<td>'.$langs->trans(
"NbOfRecord").
'</td>';
273 $sql =
"SELECT name, type FROM sqlite_master where type='table' and name not like 'sqlite%' ORDER BY name";
274 $resql = $db->query($sql);
277 while ($row = $db->fetch_row($resql)) {
278 $rescount = $db->query(
"SELECT COUNT(*) FROM ".$row[0]);
280 $row_count = $db->fetch_row($rescount);
281 $count = $row_count[0];
286 print
'<tr class="oddeven">';
287 print
'<td>'.($i+1).
'</td>';
288 print
'<td>'.$row[0].
'</td>';
289 print
'<td>'.$count.
'</td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.