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