28if (! defined(
'CSRFCHECK_WITH_TOKEN')) {
29 define(
'CSRFCHECK_WITH_TOKEN',
'1');
33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43$table =
GETPOST(
'table',
'aZ09');
44$action =
GETPOST(
'action',
'aZ09');
51if ($action ==
'convert') {
52 $sql =
"ALTER TABLE ".$db->sanitize($table).
" ENGINE=INNODB";
55if ($action ==
'convertutf8') {
56 $collation =
'utf8_unicode_ci';
57 $defaultcollation = $db->getDefaultCollationDatabase();
58 if (preg_match(
'/general/', $defaultcollation)) {
59 $collation =
'utf8_general_ci';
61 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CHARACTER SET utf8 COLLATE ".$db->sanitize($collation);
62 $resql1 = $db->query($sql);
66 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CONVERT TO CHARACTER SET utf8 COLLATE ".$db->sanitize($collation);
67 $resql2 = $db->query($sql);
73if ($action ==
'convertutf8mb4') {
74 $collation =
'utf8mb4_unicode_ci';
75 $defaultcollation = $db->getDefaultCollationDatabase();
76 if (preg_match(
'/general/', $defaultcollation)) {
77 $collation =
'utf8mb4_general_ci';
79 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CHARACTER SET utf8mb4 COLLATE ".$db->sanitize($collation);
80 $resql1 = $db->query($sql);
84 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CONVERT TO CHARACTER SET utf8mb4 COLLATE ".$db->sanitize($collation);
85 $resql2 = $db->query($sql);
91if ($action ==
'convertdynamic') {
92 $sql =
"ALTER TABLE ".$db->sanitize($table).
" ROW_FORMAT=DYNAMIC;";
101llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-database_tables');
103print
load_fiche_titre($langs->trans(
"Tables").
" ".ucfirst($conf->db->type),
'',
'title_setup');
108if (preg_match(
'/mysql/i', $conf->db->type)) {
109 $sql =
"SHOW TABLE STATUS";
111} elseif ($conf->db->type ==
'pgsql') {
112 $sql =
"SELECT conname, contype FROM pg_constraint;";
114} elseif ($conf->db->type ==
'mssql') {
117} elseif ($conf->db->type ==
'sqlite' || $conf->db->type ==
'sqlite3') {
124 print $langs->trans(
"FeatureNotAvailableWithThisDatabaseDriver");
128 print
'<div class="div-table-responsive-no-min">';
129 print
'<table class="noborder">';
130 print
'<tr class="liste_titre">';
132 print
'<td>'.$langs->trans(
"TableName").
'</td>';
133 print
'<td colspan="2">'.$langs->trans(
"Type").
'</td>';
134 print
'<td>'.$langs->trans(
"Format").
'</td>';
135 print
'<td class="right">'.$langs->trans(
"NbOfRecord").
'</td>';
136 print
'<td class="right">Avg_row_length</td>';
137 print
'<td class="right">Data_length</td>';
138 print
'<td class="right">Max_Data_length</td>';
139 print
'<td class="right">Index_length</td>';
140 print
'<td class="right">Increment</td>';
141 print
'<td class="right">Last check</td>';
142 print
'<td class="right">Collation</td>';
145 $arrayoffilesrich =
dol_dir_list(DOL_DOCUMENT_ROOT.
'/install/mysql/tables/',
'files', 0,
'\.sql$');
146 $arrayoffiles = array();
147 $arrayoftablesautocreated = array();
148 foreach ($arrayoffilesrich as $value) {
150 $shortsqlfilename = preg_replace(
'/\-[a-z]+\./',
'.', $value[
'name']);
151 $arrayoffiles[$value[
'name']] = $shortsqlfilename;
152 if ($value[
'name'] == $shortsqlfilename && ! preg_match(
'/\.key\.sql$/', $value[
'name'])) {
154 $arrayoftablesautocreated[$value[
'name']] = $shortsqlfilename;
159 $sql =
"SHOW TABLE STATUS";
161 $resql = $db->query($sql);
163 $num = $db->num_rows($resql);
166 $obj = $db->fetch_object($resql);
168 print
'<tr class="oddeven">';
170 print
'<td>'.($i + 1).
'</td>';
171 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($obj->Name).
'"><a href="dbtable.php?table='.urlencode($obj->Name).
'">'.$obj->Name.
'</a>';
172 $tablename = preg_replace(
'/^'.MAIN_DB_PREFIX.
'/',
'llx_', $obj->Name);
174 if (in_array($tablename.
'.sql', $arrayoffiles)) {
175 if (in_array($tablename.
'.sql', $arrayoftablesautocreated)) {
179 print
img_picto($langs->trans(
"NotAvailableByDefaultEnabledOnModuleActivation"), $img,
'class="small opacitymedium"');
183 print
img_picto($langs->trans(
"ExternalModule"), $img,
'class="small"');
186 print
'<td>'.$obj->Engine.
'</td>';
187 if (isset($obj->Engine) && $obj->Engine ==
"MyISAM") {
188 print
'<td><a class="reposition" href="database-tables.php?action=convert&table='.urlencode($obj->Name).
'&token='.
newToken().
'">'.$langs->trans(
"Convert").
' InnoDb</a></td>';
190 print
'<td> </td>';
193 print $obj->Row_format;
194 if (isset($obj->Row_format) && (in_array($obj->Row_format, array(
"Compact")))) {
195 print
'<br><a class="reposition" href="database-tables.php?action=convertdynamic&table='.urlencode($obj->Name).
'&token='.
newToken().
'">'.$langs->trans(
"Convert").
' Dynamic</a>';
198 print
'<td class="right">'.$obj->Rows.
'</td>';
199 print
'<td class="right">'.$obj->Avg_row_length.
'</td>';
200 print
'<td class="right">'.$obj->Data_length.
'</td>';
201 print
'<td class="right">'.$obj->Max_data_length.
'</td>';
202 print
'<td class="right">'.$obj->Index_length.
'</td>';
203 print
'<td class="right">'.$obj->Auto_increment.
'</td>';
204 print
'<td class="right">'.$obj->Check_time.
'</td>';
205 print
'<td class="right nowraponall">'.$obj->Collation;
207 if (isset($obj->Collation)) {
208 print
'<br><span class="opacitymedium small">'.$langs->trans(
"ConvertInto");
209 if (!in_array($obj->Collation, array(
"utf8_unicode_ci"))) {
210 print
' <a class="reposition" href="database-tables.php?action=convertutf8&table='.urlencode($obj->Name).
'&token='.
newToken().
'">utf8</a>';
212 if (!in_array($obj->Collation, array(
"utf8mb4_unicode_ci"))) {
213 print
' <a class="reposition" href="database-tables.php?action=convertutf8mb4&table='.urlencode($obj->Name).
'&token='.
newToken().
'">utf8mb4</a>';
227 print
'<div class="div-table-responsive-no-min">';
228 print
'<table class="noborder">';
229 print
'<tr class="liste_titre">';
232 print
'<td>'.$langs->trans(
"TableName").
'</td>';
233 print
'<td>Nb of tuples</td>';
234 print
'<td>Nb index fetcher.</td>';
235 print
'<td>Nb tuples insert</td>';
236 print
'<td>Nb tuples modify</td>';
237 print
'<td>Nb tuples delete</td>';
240 $sql =
"SELECT relname, seq_tup_read, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del";
241 $sql .=
" FROM pg_stat_user_tables ORDER BY relname";
243 $resql = $db->query($sql);
245 $num = $db->num_rows($resql);
248 $row = $db->fetch_row($resql);
249 print
'<tr class="oddeven">';
250 print
'<td>'.($i + 1).
'</td>';
251 print
'<td>'.$row[0].
'</td>';
252 print
'<td class="right">'.$row[1].
'</td>';
253 print
'<td class="right">'.$row[2].
'</td>';
254 print
'<td class="right">'.$row[3].
'</td>';
255 print
'<td class="right">'.$row[4].
'</td>';
256 print
'<td class="right">'.$row[5].
'</td>';
267 print
'<div class="div-table-responsive-no-min">';
268 print
'<table class="noborder">';
269 print
'<tr class="liste_titre">';
271 print
'<td>'.$langs->trans(
"TableName").
'</td>';
272 print
'<td>'.$langs->trans(
"NbOfRecord").
'</td>';
275 $sql =
"SELECT name, type FROM sqlite_master where type='table' and name not like 'sqlite%' ORDER BY name";
276 $resql = $db->query($sql);
279 while ($row = $db->fetch_row($resql)) {
280 $rescount = $db->query(
"SELECT COUNT(*) FROM ".$row[0]);
282 $row_count = $db->fetch_row($rescount);
283 $count = $row_count[0];
288 print
'<tr class="oddeven">';
289 print
'<td>'.($i + 1).
'</td>';
290 print
'<td>'.$row[0].
'</td>';
291 print
'<td>'.$count.
'</td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.