dolibarr 21.0.0-alpha
database.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28// Load Dolibarr environment
29require '../../main.inc.php';
30
31$langs->load("admin");
32
33$action = GETPOST('action', 'aZ09');
34
35if (!$user->admin) {
37}
38
39
40/*
41 * Actions
42 */
43
44if ($action == 'convertutf8unicode') { // Test on permission already done.
45 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
46 $db->query($sql);
47}
48if ($action == 'convertutf8mb4unicode') { // Test on permission already done.
49 $sql = "ALTER DATABASE CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
50 $db->query($sql);
51}
52if ($action == 'convertutf8general') { // Test on permission already done.
53 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8 COLLATE utf8_general_ci";
54 $db->query($sql);
55}
56if ($action == 'convertutf8mb4general') { // Test on permission already done.
57 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
58 $db->query($sql);
59}
60
61
62/*
63 * View
64 */
65
66$form = new Form($db);
67
68llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-system_database');
69
70print load_fiche_titre($langs->trans("InfoDatabase"), '', 'title_setup');
71
72// Database
73print '<div class="div-table-responsive-no-min">';
74print '<table class="noborder centpercent">';
75print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Database").'</td></tr>'."\n";
76print '<tr class="oddeven"><td width="300">'.$langs->trans("Version").'</td><td>'.$db::LABEL.' '.$db->getVersion().'</td></tr>'."\n";
77print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabaseServer").'</td><td>'.$conf->db->host.'</td></tr>'."\n";
78print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabasePort").'</td><td>'.(empty($conf->db->port) ? $langs->trans("Default") : $conf->db->port).'</td></tr>'."\n";
79print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabaseName").'</td><td>'.$conf->db->name.'</td></tr>'."\n";
80print '<tr class="oddeven"><td width="300">'.$langs->trans("DriverType").'</td><td>'.$conf->db->type.($db->getDriverInfo() ? ' ('.$db->getDriverInfo().')' : '').'</td></tr>'."\n";
81// @phan-suppress-next-line PhanTypeSuspiciousStringExpression (user is defined in the stdClass)
82print '<tr class="oddeven"><td width="300">'.$langs->trans("User").'</td><td>'.$conf->db->user.'</td></tr>'."\n";
83print '<tr class="oddeven"><td width="300">'.$langs->trans("Password").'</td><td>'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'</td></tr>'."\n";
84print '<tr class="oddeven"><td width="300">'.$langs->trans("DBStoringCharset").'</td><td>'.$db->getDefaultCharacterSetDatabase();
85if ($db->type == 'mysqli') {
86 $tooltipexample = "<br>SHOW VARIABLES LIKE 'character_set_database' (cached)<br>You can avoid cache effect with:<br>SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '".$db->escape($conf->db->name)."'";
87 print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetValue", $tooltipexample.'<br>'.$langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "<br>SHOW CHARSET")));
88 // We can use $db->getDefaultCharacterSetDatabase(), $db->getListOfCharacterSet(),
89}
90print '</td></tr>'."\n";
91print '<tr class="oddeven"><td width="300">'.$langs->trans("DBSortingCharset").'</td><td>';
92$defaultcollation = $db->getDefaultCollationDatabase();
93print dolPrintHTML($defaultcollation);
94global $dolibarr_main_db_collation;
95if ($db->type == 'mysqli') {
96 if ($defaultcollation != $conf->db->dolibarr_main_db_collation) {
97 print img_warning('The database default value of collation '.$defaultcollation.' differs from conf setup '.$conf->db->dolibarr_main_db_collation);
98 }
99 $tooltipexample = "<br>SHOW VARIABLES LIKE 'collation_database' (cached)<br>You can avoid cache effect with:<br>SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '".$db->escape($conf->db->name)."'";
100 print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetValue", $tooltipexample.'<br>'.$langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "<br>SHOW COLLATION")));
101 // We can use $db->getDefaultCollationDatabase(), $db->getListOfCollation();
102
103 print ' &nbsp; &nbsp; &nbsp; <span class="opacitymedium small">'.$langs->trans("ConvertInto");
104 if (!in_array($defaultcollation, array("utf8_unicode_ci"))) {
105 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8unicode&token='.newToken().'">utf8 unicode</a>';
106 }
107 if (!in_array($defaultcollation, array("utf8_general_ci"))) {
108 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8general&token='.newToken().'">utf8 general</a>';
109 }
110 if (!in_array($defaultcollation, array("utf8mb4_unicode_ci"))) {
111 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8mb4unicode&&token='.newToken().'">utf8mb4 unicode</a>';
112 }
113 if (!in_array($defaultcollation, array("utf8mb4_general_ci"))) {
114 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8mb4general&&token='.newToken().'">utf8mb4 general</a>';
115 }
116}
117print '</td></tr>'."\n";
118print '</table>';
119print '</div>';
120
121// Tables
122print '<br>';
123print '<div class="div-table-responsive-no-min">';
124print '<table class="noborder centpercent">';
125print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Tables").'</td></tr>'."\n";
126print '<tr class="oddeven"><td class=""><a href="'.DOL_URL_ROOT.'/admin/system/database-tables.php?mainmenu=home">'.img_picto('', 'list', 'class="pictofixedwidth"').$langs->trans("List").'</a></td></tr>'."\n";
127print '</table>';
128print '</div>';
129
130$listofvars = $db->getServerParametersValues();
131$listofstatus = $db->getServerStatusValues();
132$arraylist = array('listofvars', 'listofstatus');
133
134if (!count($listofvars) && !count($listofstatus)) {
135 print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
136} else {
137 foreach ($arraylist as $listname) {
138 print '<br>';
139 print '<div class="div-table-responsive-no-min">';
140 print '<table class="noborder centpercent">';
141 print '<tr class="liste_titre">';
142 print '<td width="300">'.$langs->trans("Parameters").'</td>';
143 print '<td></td>';
144 print '</tr>'."\n";
145
146 // arraytest is an array of test to do
147 $arraytest = array();
148 if (preg_match('/mysql/i', $db->type)) {
149 $arraytest = array(
150 'character_set_database' => array('var' => 'dolibarr_main_db_character_set', 'valifempty' => 'utf8'),
151 'collation_database' => array('var' => 'dolibarr_main_db_collation', 'valifempty' => 'utf8_unicode_ci')
152 );
153 }
154
155 $listtouse = array();
156 if ($listname == 'listofvars') {
157 $listtouse = $listofvars;
158 }
159 if ($listname == 'listofstatus') {
160 $listtouse = $listofstatus;
161 }
162
163 foreach ($listtouse as $param => $paramval) {
164 print '<tr class="oddeven">';
165 print '<td>';
166 print $param;
167 print '</td>';
168 print '<td class="wordbreak">';
169 $show = 0;
170 $text = '';
171 foreach ($arraytest as $key => $val) {
172 if ($key != $param) {
173 continue;
174 }
175 $tmpvar = $val['var'];
176 $val2 = ${$tmpvar};
177 $text = 'Should be in line with value of param <b>'.$val['var'].'</b> thas is <b>'.($val2 ? $val2 : "'' (=".$val['valifempty'].")").'</b>';
178 $show = 1;
179 }
180 if ($show == 0) {
181 print $paramval;
182 }
183 if ($show == 1) {
184 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
185 print $form->textwithpicto($paramval, $text);
186 }
187 if ($show == 2) {
188 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
189 print $form->textwithpicto($paramval, $text, 1, 'warning');
190 }
191 print '</td>';
192 print '</tr>'."\n";
193 }
194 print '</table>'."\n";
195 print '</div>';
196 }
197}
198
199// End of page
200llxFooter();
201$db->close();
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.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
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.