dolibarr 23.0.3
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-2025 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
43$langs->load("admin");
44
45$action = GETPOST('action', 'aZ09');
46
47if (!$user->admin) {
49}
50
51
52/*
53 * Actions
54 */
55
56$logsql = '';
57$resultsql = null;
58
59if ($action == 'convertutf8unicode') { // Test on permission already done.
60 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
61 $logsql .= $sql.'<br>';
62 $resultsql = $db->query($sql);
63}
64if ($action == 'convertutf8mb4unicode') { // Test on permission already done.
65 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
66 $logsql .= $sql.'<br>';
67 $resultsql = $db->query($sql);
68}
69if ($action == 'convertutf8general') { // Test on permission already done.
70 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8 COLLATE utf8_general_ci";
71 $logsql .= $sql.'<br>';
72 $resultsql = $db->query($sql);
73}
74if ($action == 'convertutf8mb4general') { // Test on permission already done.
75 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
76 $logsql .= $sql.'<br>';
77 $resultsql = $db->query($sql);
78}
79
80
81/*
82 * View
83 */
84
85$form = new Form($db);
86
87llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-system_database');
88
89print load_fiche_titre($langs->trans("InfoDatabase"), '', 'title_setup');
90
91if ($logsql) {
92 print info_admin($logsql.' '.(empty($resultsql) ? ' => KO '.$db->lasterror() : ' => OK'));
93}
94
95// Database
96print '<div class="div-table-responsive-no-min">';
97print '<table class="noborder centpercent">';
98print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Database").'</td></tr>'."\n";
99print '<tr class="oddeven"><td width="300">'.$langs->trans("Version").'</td><td>'.$db::LABEL.' '.$db->getVersion().'</td></tr>'."\n";
100print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabaseServer").'</td><td>'.$conf->db->host.'</td></tr>'."\n";
101print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabasePort").'</td><td>'.(empty($conf->db->port) ? $langs->trans("Default") : $conf->db->port).'</td></tr>'."\n";
102print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabaseName").'</td><td>'.$conf->db->name.'</td></tr>'."\n";
103print '<tr class="oddeven"><td width="300">'.$langs->trans("DriverType").'</td><td>'.$conf->db->type.($db->getDriverInfo() ? ' ('.$db->getDriverInfo().')' : '').'</td></tr>'."\n";
104// @phan-suppress-next-line PhanTypeSuspiciousStringExpression (user is defined in the stdClass)
105print '<tr class="oddeven"><td width="300">'.$langs->trans("User").'</td><td>'.$conf->db->user.'</td></tr>'."\n";
106print '<tr class="oddeven"><td width="300">'.$langs->trans("Password").'</td><td>'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'</td></tr>'."\n";
107print '<tr class="oddeven"><td width="300">'.$langs->trans("DBStoringCharset").'</td><td>'.$db->getDefaultCharacterSetDatabase();
108if ($db->type == 'mysqli') {
109 $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)."'";
110 print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetValue", $tooltipexample.'<br>'.$langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "<br>SHOW CHARSET")."<br><br>Example to change value: ALTER DATABASE ".$conf->db->name." CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"), 1, 'help', 'valignmiddle', 0, 3, 'tooltipcharset');
111 // We can use $db->getDefaultCharacterSetDatabase(), $db->getListOfCharacterSet(),
112}
113print '</td></tr>'."\n";
114print '<tr class="oddeven"><td width="300">'.$langs->trans("DBSortingCharset").'</td><td>';
115$defaultcollation = $db->getDefaultCollationDatabase();
116print dolPrintHTML($defaultcollation);
117global $dolibarr_main_db_collation;
118if ($db->type == 'mysqli') {
119 if ($defaultcollation != $conf->db->dolibarr_main_db_collation) {
120 print img_warning('The database default value of collation '.$defaultcollation.' differs from conf setup '.$conf->db->dolibarr_main_db_collation);
121 }
122 $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)."'";
123 print ' '.$form->textwithpicto('', $langs->transnoentitiesnoconv("HelpMariaDBToGetValue", $tooltipexample.'<br>'.$langs->transnoentitiesnoconv("HelpMariaDBToGetPossibleValues", "<br>SHOW COLLATION")."<br><br>Example to change value: ALTER DATABASE ".$conf->db->name." CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"), 1, 'help', 'valignmiddle', 0, 3, 'tooltipcollation');
124 // We can use $db->getDefaultCollationDatabase(), $db->getListOfCollation();
125
126 print ' &nbsp; &nbsp; &nbsp; <span class="opacitymedium small">'.$langs->trans("ConvertInto");
127 if (!in_array($defaultcollation, array("utf8_unicode_ci"))) {
128 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8unicode&token='.newToken().'">utf8 unicode</a>';
129 }
130 if (!in_array($defaultcollation, array("utf8_general_ci"))) {
131 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8general&token='.newToken().'">utf8 general</a>';
132 }
133 if (!in_array($defaultcollation, array("utf8mb4_unicode_ci"))) {
134 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8mb4unicode&&token='.newToken().'">utf8mb4 unicode</a>';
135 }
136 if (!in_array($defaultcollation, array("utf8mb4_general_ci"))) {
137 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8mb4general&&token='.newToken().'">utf8mb4 general</a>';
138 }
139}
140print '</td></tr>'."\n";
141print '</table>';
142print '</div>';
143
144// Tables
145print '<br>';
146print '<div class="div-table-responsive-no-min">';
147print '<table class="noborder centpercent">';
148print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Tables").'</td></tr>'."\n";
149print '<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";
150print '</table>';
151print '</div>';
152
153$listofvars = $db->getServerParametersValues();
154$listofstatus = $db->getServerStatusValues();
155$arraylist = array('listofvars', 'listofstatus');
156
157if (!count($listofvars) && !count($listofstatus)) {
158 print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
159} else {
160 foreach ($arraylist as $listname) {
161 print '<br>';
162 print '<div class="div-table-responsive-no-min">';
163 print '<table class="noborder centpercent">';
164 print '<tr class="liste_titre">';
165 print '<td width="300">'.$langs->trans("Parameters").'</td>';
166 print '<td></td>';
167 print '</tr>'."\n";
168
169 // arraytest is an array of test to do
170 $arraytest = array();
171 if (preg_match('/mysql/i', $db->type)) {
172 $arraytest = array(
173 'character_set_database' => array('var' => 'dolibarr_main_db_character_set', 'valifempty' => 'utf8'),
174 'collation_database' => array('var' => 'dolibarr_main_db_collation', 'valifempty' => 'utf8_unicode_ci')
175 );
176 }
177
178 $listtouse = array();
179 if ($listname == 'listofvars') {
180 $listtouse = $listofvars;
181 }
182 if ($listname == 'listofstatus') {
183 $listtouse = $listofstatus;
184 }
185
186 foreach ($listtouse as $param => $paramval) {
187 print '<tr class="oddeven">';
188 print '<td>';
189 print $param;
190 print '</td>';
191 print '<td class="wordbreak">';
192 $show = 0;
193 $text = '';
194 foreach ($arraytest as $key => $val) {
195 if ($key != $param) {
196 continue;
197 }
198 $tmpvar = $val['var'];
199 $val2 = ${$tmpvar};
200 $text = 'Should be in line with value of param <b>'.$val['var'].'</b> thas is <b>'.($val2 ? $val2 : "'' (=".$val['valifempty'].")").'</b>';
201 $show = 1;
202 }
203 if ($show == 0) {
204 print $paramval;
205 }
206 if ($show == 1) {
207 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
208 print $form->textwithpicto($paramval, $text);
209 }
210 if ($show == 2) {
211 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
212 print $form->textwithpicto($paramval, $text, 1, 'warning');
213 }
214 print '</td>';
215 print '</tr>'."\n";
216 }
217 print '</table>'."\n";
218 print '</div>';
219 }
220}
221
222// End of page
223llxFooter();
224$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.