dolibarr 22.0.5
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
56if ($action == 'convertutf8unicode') { // Test on permission already done.
57 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
58 $db->query($sql);
59}
60if ($action == 'convertutf8mb4unicode') { // Test on permission already done.
61 $sql = "ALTER DATABASE CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
62 $db->query($sql);
63}
64if ($action == 'convertutf8general') { // Test on permission already done.
65 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8 COLLATE utf8_general_ci";
66 $db->query($sql);
67}
68if ($action == 'convertutf8mb4general') { // Test on permission already done.
69 $sql = "ALTER DATABASE ".$db->sanitize($db->database_name)." CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
70 $db->query($sql);
71}
72
73
74/*
75 * View
76 */
77
78$form = new Form($db);
79
80llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-system_database');
81
82print load_fiche_titre($langs->trans("InfoDatabase"), '', 'title_setup');
83
84// Database
85print '<div class="div-table-responsive-no-min">';
86print '<table class="noborder centpercent">';
87print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Database").'</td></tr>'."\n";
88print '<tr class="oddeven"><td width="300">'.$langs->trans("Version").'</td><td>'.$db::LABEL.' '.$db->getVersion().'</td></tr>'."\n";
89print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabaseServer").'</td><td>'.$conf->db->host.'</td></tr>'."\n";
90print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabasePort").'</td><td>'.(empty($conf->db->port) ? $langs->trans("Default") : $conf->db->port).'</td></tr>'."\n";
91print '<tr class="oddeven"><td width="300">'.$langs->trans("DatabaseName").'</td><td>'.$conf->db->name.'</td></tr>'."\n";
92print '<tr class="oddeven"><td width="300">'.$langs->trans("DriverType").'</td><td>'.$conf->db->type.($db->getDriverInfo() ? ' ('.$db->getDriverInfo().')' : '').'</td></tr>'."\n";
93// @phan-suppress-next-line PhanTypeSuspiciousStringExpression (user is defined in the stdClass)
94print '<tr class="oddeven"><td width="300">'.$langs->trans("User").'</td><td>'.$conf->db->user.'</td></tr>'."\n";
95print '<tr class="oddeven"><td width="300">'.$langs->trans("Password").'</td><td>'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'</td></tr>'."\n";
96print '<tr class="oddeven"><td width="300">'.$langs->trans("DBStoringCharset").'</td><td>'.$db->getDefaultCharacterSetDatabase();
97if ($db->type == 'mysqli') {
98 $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)."'";
99 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_general_ci;"));
100 // We can use $db->getDefaultCharacterSetDatabase(), $db->getListOfCharacterSet(),
101}
102print '</td></tr>'."\n";
103print '<tr class="oddeven"><td width="300">'.$langs->trans("DBSortingCharset").'</td><td>';
104$defaultcollation = $db->getDefaultCollationDatabase();
105print dolPrintHTML($defaultcollation);
106global $dolibarr_main_db_collation;
107if ($db->type == 'mysqli') {
108 if ($defaultcollation != $conf->db->dolibarr_main_db_collation) {
109 print img_warning('The database default value of collation '.$defaultcollation.' differs from conf setup '.$conf->db->dolibarr_main_db_collation);
110 }
111 $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)."'";
112 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_general_ci;"));
113 // We can use $db->getDefaultCollationDatabase(), $db->getListOfCollation();
114
115 print ' &nbsp; &nbsp; &nbsp; <span class="opacitymedium small">'.$langs->trans("ConvertInto");
116 if (!in_array($defaultcollation, array("utf8_unicode_ci"))) {
117 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8unicode&token='.newToken().'">utf8 unicode</a>';
118 }
119 if (!in_array($defaultcollation, array("utf8_general_ci"))) {
120 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8general&token='.newToken().'">utf8 general</a>';
121 }
122 if (!in_array($defaultcollation, array("utf8mb4_unicode_ci"))) {
123 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8mb4unicode&&token='.newToken().'">utf8mb4 unicode</a>';
124 }
125 if (!in_array($defaultcollation, array("utf8mb4_general_ci"))) {
126 print ' &nbsp; <a class="reposition" href="'.DOL_URL_ROOT.'/admin/system/database.php?action=convertutf8mb4general&&token='.newToken().'">utf8mb4 general</a>';
127 }
128}
129print '</td></tr>'."\n";
130print '</table>';
131print '</div>';
132
133// Tables
134print '<br>';
135print '<div class="div-table-responsive-no-min">';
136print '<table class="noborder centpercent">';
137print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Tables").'</td></tr>'."\n";
138print '<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";
139print '</table>';
140print '</div>';
141
142$listofvars = $db->getServerParametersValues();
143$listofstatus = $db->getServerStatusValues();
144$arraylist = array('listofvars', 'listofstatus');
145
146if (!count($listofvars) && !count($listofstatus)) {
147 print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
148} else {
149 foreach ($arraylist as $listname) {
150 print '<br>';
151 print '<div class="div-table-responsive-no-min">';
152 print '<table class="noborder centpercent">';
153 print '<tr class="liste_titre">';
154 print '<td width="300">'.$langs->trans("Parameters").'</td>';
155 print '<td></td>';
156 print '</tr>'."\n";
157
158 // arraytest is an array of test to do
159 $arraytest = array();
160 if (preg_match('/mysql/i', $db->type)) {
161 $arraytest = array(
162 'character_set_database' => array('var' => 'dolibarr_main_db_character_set', 'valifempty' => 'utf8'),
163 'collation_database' => array('var' => 'dolibarr_main_db_collation', 'valifempty' => 'utf8_unicode_ci')
164 );
165 }
166
167 $listtouse = array();
168 if ($listname == 'listofvars') {
169 $listtouse = $listofvars;
170 }
171 if ($listname == 'listofstatus') {
172 $listtouse = $listofstatus;
173 }
174
175 foreach ($listtouse as $param => $paramval) {
176 print '<tr class="oddeven">';
177 print '<td>';
178 print $param;
179 print '</td>';
180 print '<td class="wordbreak">';
181 $show = 0;
182 $text = '';
183 foreach ($arraytest as $key => $val) {
184 if ($key != $param) {
185 continue;
186 }
187 $tmpvar = $val['var'];
188 $val2 = ${$tmpvar};
189 $text = 'Should be in line with value of param <b>'.$val['var'].'</b> thas is <b>'.($val2 ? $val2 : "'' (=".$val['valifempty'].")").'</b>';
190 $show = 1;
191 }
192 if ($show == 0) {
193 print $paramval;
194 }
195 if ($show == 1) {
196 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
197 print $form->textwithpicto($paramval, $text);
198 }
199 if ($show == 2) {
200 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
201 print $form->textwithpicto($paramval, $text, 1, 'warning');
202 }
203 print '</td>';
204 print '</tr>'."\n";
205 }
206 print '</table>'."\n";
207 print '</div>';
208 }
209}
210
211// End of page
212llxFooter();
213$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.
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, $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.