28require_once DOL_DOCUMENT_ROOT.
'/core/db/DoliDB.class.php';
41 const LABEL =
'MySQL or MariaDB';
64 if (!empty($conf->db->character_set)) {
65 $this->forcecharset = $conf->db->character_set;
67 if (!empty($conf->db->dolibarr_main_db_collation)) {
68 $this->forcecollate = $conf->db->dolibarr_main_db_collation;
71 $this->database_user = $user;
72 $this->database_host = $host;
73 $this->database_port = $port;
75 $this->transaction_opened = 0;
79 if (!class_exists(
'mysqli')) {
80 $this->connected =
false;
82 $this->
error =
"Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.";
83 dol_syslog(get_class($this).
"::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.", LOG_ERR);
87 $this->connected =
false;
89 $this->
error = $langs->trans(
"ErrorWrongHostParameter");
90 dol_syslog(get_class($this).
"::DoliDBMysqli : Connect error, wrong host parameters", LOG_ERR);
95 $this->db = $this->
connect($host, $user, $pass,
'', $port);
97 if ($this->db && empty($this->db->connect_errno)) {
98 $this->connected =
true;
101 $this->connected =
false;
103 $this->
error = empty($this->db) ?
'Failed to connect' : $this->db->connect_error;
104 dol_syslog(get_class($this).
"::DoliDBMysqli Connect error: ".$this->
error, LOG_ERR);
108 if ($this->connected && $name) {
110 $this->database_selected =
true;
111 $this->database_name = $name;
115 $clientmustbe = empty($conf->db->character_set) ?
'utf8' : $conf->db->character_set;
116 if (preg_match(
'/latin1/', $clientmustbe)) {
117 $clientmustbe =
'utf8';
120 $disableforcecharset = 0;
121 if (empty($disableforcecharset) && $this->db->character_set_name() != $clientmustbe) {
124 dol_syslog(get_class($this).
"::DoliDBMysqli You should set the \$dolibarr_main_db_character_set and \$dolibarr_main_db_collation for the PHP to the one of the database ".$this->db->character_set_name(), LOG_WARNING);
125 $this->db->set_charset($clientmustbe);
127 print
'Failed to force character set to '.$clientmustbe.
" according to setup to match the one of the server database.<br>\n";
128 print $e->getMessage();
130 if ($clientmustbe !=
'utf8') {
131 print
'Edit conf/conf.php file to set a charset "utf8" instead of "'.$clientmustbe.
'".'.
"\n";
136 $collation = (empty($conf) ?
'utf8_unicode_ci' : $conf->db->dolibarr_main_db_collation);
137 if (preg_match(
'/latin1/', $collation)) {
138 $collation =
'utf8_unicode_ci';
141 if (!preg_match(
'/general/', $collation)) {
142 $this->db->query(
"SET collation_connection = ".$collation);
146 $this->database_selected =
false;
147 $this->database_name =
'';
150 dol_syslog(get_class($this).
"::DoliDBMysqli : Select_db error ".$this->
error, LOG_ERR);
154 $this->database_selected =
false;
156 if ($this->connected) {
158 $clientmustbe = empty($conf->db->character_set) ?
'utf8' : $conf->db->character_set;
159 if (preg_match(
'/latin1/', $clientmustbe)) {
160 $clientmustbe =
'utf8';
162 if (preg_match(
'/utf8mb4/', $clientmustbe)) {
163 $clientmustbe =
'utf8';
166 if ($this->db->character_set_name() != $clientmustbe) {
167 $this->db->set_charset($clientmustbe);
169 $collation = $conf->db->dolibarr_main_db_collation;
170 if (preg_match(
'/latin1/', $collation)) {
171 $collation =
'utf8_unicode_ci';
173 if (preg_match(
'/utf8mb4/', $collation)) {
174 $collation =
'utf8_unicode_ci';
177 if (!preg_match(
'/general/', $collation)) {
178 $this->db->query(
"SET collation_connection = ".$collation);
194 return " FORCE INDEX(".preg_replace(
'/[^a-z0-9_]/',
'', $nameofindex).
")";
221 dol_syslog(get_class($this).
"::select_db database=".$database, LOG_DEBUG);
224 $result = $this->db->select_db($database);
243 public function connect($host, $login, $passwd, $name, $port = 0)
245 dol_syslog(get_class($this).
"::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name", LOG_DEBUG);
251 if (!class_exists(
'mysqli')) {
254 if (strpos($host,
'ssl://') === 0) {
255 $tmp =
new mysqliDoli($host, $login, $passwd, $name, $port);
257 $tmp =
new mysqli($host, $login, $passwd, $name, $port);
260 dol_syslog(get_class($this).
"::connect failed", LOG_DEBUG);
272 return $this->db->server_info;
282 return $this->db->client_info;
295 if ($this->transaction_opened > 0) {
296 dol_syslog(get_class($this).
"::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR);
298 $this->connected =
false;
299 return $this->db->close();
316 public function query($query, $usesavepoint = 0,
$type =
'auto', $result_mode = 0)
318 global $conf, $dolibarr_main_db_readonly;
320 $query = trim($query);
322 if (!in_array($query, array(
'BEGIN',
'COMMIT',
'ROLLBACK'))) {
323 $SYSLOG_SQL_LIMIT = 10000;
324 dol_syslog(
'sql='.substr($query, 0, $SYSLOG_SQL_LIMIT), LOG_DEBUG);
330 if (!empty($dolibarr_main_db_readonly)) {
331 if (preg_match(
'/^(INSERT|UPDATE|REPLACE|DELETE|CREATE|ALTER|TRUNCATE|DROP)/i', $query)) {
332 $this->
lasterror =
'Application in read-only mode';
340 if (!$this->database_name) {
342 $ret = $this->db->query($query, $result_mode);
344 $ret = $this->db->query($query, $result_mode);
347 dol_syslog(get_class($this).
"::query Exception in query instead of returning an error: ".$e->getMessage(), LOG_ERR);
351 if (!preg_match(
"/^COMMIT/i", $query) && !preg_match(
"/^ROLLBACK/i", $query)) {
359 dol_syslog(get_class($this).
"::query SQL Error query: ".$query, LOG_ERR);
361 dol_syslog(get_class($this).
"::query SQL Error message: ".$this->
lasterrno.
" ".$this->lasterror, LOG_ERR);
365 $this->_results = $ret;
382 if (!is_object($resultset)) {
383 $resultset = $this->_results;
385 return $resultset->fetch_object();
400 if (!is_object($resultset)) {
401 $resultset = $this->_results;
403 return $resultset->fetch_array();
417 if (!is_bool($resultset)) {
418 if (!is_object($resultset)) {
419 $resultset = $this->_results;
421 return $resultset->fetch_row();
440 if (!is_object($resultset)) {
441 $resultset = $this->_results;
443 return isset($resultset->num_rows) ? $resultset->num_rows : 0;
458 if (!is_object($resultset)) {
459 $resultset = $this->_results;
463 return $this->db->affected_rows;
473 public function free($resultset =
null)
476 if (!is_object($resultset)) {
477 $resultset = $this->_results;
480 if (is_object($resultset)) {
481 $resultset->free_result();
493 return $this->db->real_escape_string((
string) $stringtoencode);
504 return str_replace(array(
'\\',
'_',
'%'), array(
'\\\\',
'\_',
'\%'), (
string) $stringtoencode);
514 if (!$this->connected) {
516 return 'DB_ERROR_FAILED_TO_CONNECT';
519 $errorcode_map = array(
520 1004 =>
'DB_ERROR_CANNOT_CREATE',
521 1005 =>
'DB_ERROR_CANNOT_CREATE',
522 1006 =>
'DB_ERROR_CANNOT_CREATE',
523 1007 =>
'DB_ERROR_ALREADY_EXISTS',
524 1008 =>
'DB_ERROR_CANNOT_DROP',
525 1022 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
526 1025 =>
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
527 1044 =>
'DB_ERROR_ACCESSDENIED',
528 1046 =>
'DB_ERROR_NODBSELECTED',
529 1048 =>
'DB_ERROR_CONSTRAINT',
530 1050 =>
'DB_ERROR_TABLE_ALREADY_EXISTS',
531 1051 =>
'DB_ERROR_NOSUCHTABLE',
532 1054 =>
'DB_ERROR_NOSUCHFIELD',
533 1060 =>
'DB_ERROR_COLUMN_ALREADY_EXISTS',
534 1061 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
535 1062 =>
'DB_ERROR_RECORD_ALREADY_EXISTS',
536 1064 =>
'DB_ERROR_SYNTAX',
537 1068 =>
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
538 1075 =>
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
539 1091 =>
'DB_ERROR_NOSUCHFIELD',
540 1100 =>
'DB_ERROR_NOT_LOCKED',
541 1136 =>
'DB_ERROR_VALUE_COUNT_ON_ROW',
542 1146 =>
'DB_ERROR_NOSUCHTABLE',
543 1215 =>
'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT',
544 1216 =>
'DB_ERROR_NO_PARENT',
545 1217 =>
'DB_ERROR_CHILD_EXISTS',
546 1396 =>
'DB_ERROR_USER_ALREADY_EXISTS',
547 1451 =>
'DB_ERROR_CHILD_EXISTS',
548 1826 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
551 if (isset($errorcode_map[$this->db->errno])) {
552 return $errorcode_map[$this->db->errno];
554 $errno = $this->db->errno;
555 return ($errno ?
'DB_ERROR_'.$errno :
'0');
566 if (!$this->connected) {
568 return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions';
570 return $this->db->error;
585 return $this->db->insert_id;
596 public function encrypt($fieldorvalue, $withQuotes = 1)
601 $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0);
604 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey :
'');
606 $escapedstringwithquotes = ($withQuotes ?
"'" :
"").$this->
escape($fieldorvalue).($withQuotes ?
"'" :
"");
608 if ($cryptType && !empty($cryptKey)) {
609 if ($cryptType == 2) {
610 $escapedstringwithquotes =
"AES_ENCRYPT(".$escapedstringwithquotes.
", '".$this->
escape($cryptKey).
"')";
611 } elseif ($cryptType == 1) {
612 $escapedstringwithquotes =
"DES_ENCRYPT(".$escapedstringwithquotes.
", '".$this->
escape($cryptKey).
"')";
616 return $escapedstringwithquotes;
630 $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0);
633 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey :
'');
637 if ($cryptType && !empty($cryptKey)) {
638 if ($cryptType == 2) {
639 $return =
'AES_DECRYPT('.$value.
',\''.$cryptKey.
'\')
';
640 } elseif ($cryptType == 1) {
641 $return = 'DES_DECRYPT(
'.$value.',\
''.$cryptKey.
'\')
';
649 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
655 public function DDLGetConnectId()
658 $resql = $this->query('SELECT CONNECTION_ID()
');
660 $row = $this->fetch_row($resql);
667 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
679 public function DDLCreateDb($database, $charset = '
', $collation = '', $owner = '')
682 if (empty($charset)) {
683 $charset = $this->forcecharset;
685 if (empty($collation)) {
686 $collation = $this->forcecollate;
689 // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
690 $sql = "CREATE DATABASE `".$this->escape($database)."`";
691 $sql .= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`";
693 dol_syslog($sql, LOG_DEBUG);
694 $ret = $this->query($sql);
696 // We try again for compatibility with Mysql < 4.1.1
697 $sql = "CREATE DATABASE `".$this->escape($database)."`";
698 dol_syslog($sql, LOG_DEBUG);
699 $ret = $this->query($sql);
704 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
712 public function DDLListTables($database, $table = '
')
715 $listtables = array();
719 $tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i
', '', $table);
721 $like = "LIKE '".$this->escape($tmptable)."'";
723 $tmpdatabase = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $database);
725 $sql = "SHOW TABLES FROM `".$tmpdatabase."` ".$like.";";
727 $result = $this->query($sql);
729 while ($row = $this->fetch_row($result)) {
730 $listtables[] = $row[0];
736 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
744 public function DDLListTablesFull($database, $table = '
')
747 $listtables = array();
751 $tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i
', '', $table);
753 $like = "LIKE '".$this->escape($tmptable)."'";
755 $tmpdatabase = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $database);
757 $sql = "SHOW FULL TABLES FROM `".$tmpdatabase."` ".$like.";";
759 $result = $this->query($sql);
761 while ($row = $this->fetch_row($result)) {
762 $listtables[] = $row;
768 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
775 public function DDLInfoTable($table)
778 $infotables = array();
780 $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $table);
782 $sql = "SHOW FULL COLUMNS FROM ".$tmptable.";";
784 dol_syslog($sql, LOG_DEBUG);
785 $result = $this->query($sql);
787 while ($row = $this->fetch_row($result)) {
788 $infotables[] = $row;
794 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
807 public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null)
810 // FIXME: $fulltext_keys parameter is unused
813 $sqluq = $sqlk = array();
815 // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra
816 // ex. : $fields['rowid'] = array('type'=>'int','value
'=>'11
','null'=>'not
null','extra
'=> 'auto_increment
');
817 $sql = "CREATE TABLE ".$table."(";
819 $sqlfields = array();
820 foreach ($fields as $field_name => $field_desc) {
821 $sqlfields[$i] = $field_name." ";
822 $sqlfields[$i] .= $field_desc['type'];
823 if (preg_match("/^[^\s]/i", $field_desc['value
'])) {
824 $sqlfields[$i] .= "(".$field_desc['value
'].")";
826 if (preg_match("/^[^\s]/i", $field_desc['attribute
'])) {
827 $sqlfields[$i] .= " ".$field_desc['attribute
'];
829 if (preg_match("/^[^\s]/i", $field_desc['default'])) {
830 if ((preg_match("/null/i", $field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i", $field_desc['default']))) {
831 $sqlfields[$i] .= " default ".$field_desc['default'];
833 $sqlfields[$i] .= " default '".$this->escape($field_desc['default'])."'";
836 if (preg_match("/^[^\s]/i", $field_desc['null'])) {
837 $sqlfields[$i] .= " ".$field_desc['null'];
839 if (preg_match("/^[^\s]/i", $field_desc['extra
'])) {
840 $sqlfields[$i] .= " ".$field_desc['extra
'];
844 if ($primary_key != "") {
845 $pk = "primary key(".$primary_key.")";
848 if (is_array($unique_keys)) {
850 foreach ($unique_keys as $key => $value) {
851 $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$this->escape($value)."')";
855 if (is_array($keys)) {
857 foreach ($keys as $key => $value) {
858 $sqlk[$i] = "KEY ".$key." (".$value.")";
862 $sql .= implode(',
', $sqlfields);
863 if ($primary_key != "") {
866 if ($unique_keys != "") {
867 $sql .= ",".implode(',
', $sqluq);
869 if (is_array($keys)) {
870 $sql .= ",".implode(',
', $sqlk);
872 $sql .= ") engine=".$type;
874 if (!$this->query($sql)) {
881 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
888 public function DDLDropTable($table)
891 $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $table);
893 $sql = "DROP TABLE ".$tmptable;
895 if (!$this->query($sql)) {
902 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
910 public function DDLDescTable($table, $field = "")
913 $sql = "DESC ".$table." ".$field;
915 dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG);
916 $this->_results = $this->query($sql);
917 return $this->_results;
920 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
930 public function DDLAddField($table, $field_name, $field_desc, $field_position = "")
933 // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
934 // ex. : $field_desc = array('
type'=>'int','value
'=>'11
','null'=>'not
null','extra
'=> 'auto_increment
');
935 $sql = "ALTER TABLE ".$table." ADD ".$field_name." ";
936 $sql .= $field_desc['type'];
937 if (preg_match("/^[^\s]/i", $field_desc['value
'])) {
938 if (!in_array($field_desc['type'], array('date
', 'datetime
')) && $field_desc['value
']) {
939 $sql .= "(".$field_desc['value
'].")";
942 if (isset($field_desc['attribute
']) && preg_match("/^[^\s]/i", $field_desc['attribute
'])) {
943 $sql .= " ".$field_desc['attribute
'];
945 if (isset($field_desc['null']) && preg_match("/^[^\s]/i", $field_desc['null'])) {
946 $sql .= " ".$field_desc['null'];
948 if (isset($field_desc['default']) && preg_match("/^[^\s]/i", $field_desc['default'])) {
949 if (preg_match("/null/i", $field_desc['default'])) {
950 $sql .= " default ".$field_desc['default'];
952 $sql .= " default '".$this->escape($field_desc['default'])."'";
955 if (isset($field_desc['extra
']) && preg_match("/^[^\s]/i", $field_desc['extra
'])) {
956 $sql .= " ".$field_desc['extra
'];
958 $sql .= " ".$field_position;
960 dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG);
961 if ($this->query($sql)) {
967 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
976 public function DDLUpdateField($table, $field_name, $field_desc)
979 $sql = "ALTER TABLE ".$table;
980 $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['
type'];
981 if (in_array($field_desc['type'], array('double', 'tinyint
', 'int', 'varchar
')) && $field_desc['value
']) {
982 $sql .= "(".$field_desc['value
'].")";
984 if ($field_desc['null'] == 'not
null' || $field_desc['null'] == 'NOT NULL
') {
985 // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL
986 if ($field_desc['type'] == 'varchar
' || $field_desc['type'] == 'text
') {
987 $sqlbis = "UPDATE ".$table." SET ".$field_name." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
988 $this->query($sqlbis);
989 } elseif ($field_desc['type'] == 'tinyint
' || $field_desc['type'] == 'int') {
990 $sqlbis = "UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape(isset($field_desc['default']) ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
991 $this->query($sqlbis);
997 if (isset($field_desc['default']) && $field_desc['default'] != '') {
998 if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint
' || $field_desc['type'] == 'int') {
999 $sql .= " DEFAULT ".$this->escape($field_desc['default']);
1000 } elseif ($field_desc['type'] != 'text
') {
1001 $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
1005 dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG);
1006 if (!$this->query($sql)) {
1013 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1021 public function DDLDropField($table, $field_name)
1024 $tmp_field_name = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $field_name);
1026 $sql = "ALTER TABLE ".$table." DROP COLUMN `".$tmp_field_name."`";
1027 if ($this->query($sql)) {
1030 $this->error = $this->lasterror();
1035 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1045 public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
1048 $sql = "CREATE USER '
".$this->escape($dolibarr_main_db_user)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
1049 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1050 $resql = $this->query($sql);
1052 if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS
') {
1055 // If user already exists, we continue to set permissions
1056 dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
1060 // Redo with localhost forced (sometimes user is created on %)
1061 $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'localhost
' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
1062 $resql = $this->query($sql);
1064 $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."'";
1065 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1066 $resql = $this->query($sql);
1068 $this->error = "Connected user not allowed to GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."'";
1072 $sql = "FLUSH Privileges";
1074 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG);
1075 $resql = $this->query($sql);
1090 public function getDefaultCharacterSetDatabase()
1092 $resql = $this->query("SHOW VARIABLES LIKE 'character_set_database
'");
1094 // version Mysql < 4.1.1
1095 return $this->forcecharset;
1097 $liste = $this->fetch_array($resql);
1098 $tmpval = $liste['Value
'];
1108 public function getListOfCharacterSet()
1110 $resql = $this->query('SHOW CHARSET
');
1114 while ($obj = $this->fetch_object($resql)) {
1115 $liste[$i]['charset
'] = $obj->Charset;
1119 $this->free($resql);
1121 // version Mysql < 4.1.1
1133 public function getDefaultCollationDatabase()
1135 $resql = $this->query("SHOW VARIABLES LIKE 'collation_database
'");
1137 // version Mysql < 4.1.1
1138 return $this->forcecollate;
1140 $liste = $this->fetch_array($resql);
1141 $tmpval = $liste['Value
'];
1151 public function getListOfCollation()
1153 $resql = $this->query('SHOW COLLATION
');
1157 while ($obj = $this->fetch_object($resql)) {
1158 $liste[$i]['collation
'] = $obj->Collation;
1161 $this->free($resql);
1163 // version Mysql < 4.1.1
1174 public function getPathOfDump()
1176 $fullpathofdump = '/pathtomysqldump/mysqldump
';
1178 $resql = $this->query("SHOW VARIABLES LIKE 'basedir
'");
1180 $liste = $this->fetch_array($resql);
1181 $basedir = $liste['Value
'];
1182 $fullpathofdump = $basedir.(preg_match('/\/$/
', $basedir) ? '' : '/
').'bin/mysqldump
';
1184 return $fullpathofdump;
1192 public function getPathOfRestore()
1194 $fullpathofimport = '/pathtomysql/mysql
';
1196 $resql = $this->query("SHOW VARIABLES LIKE 'basedir
'");
1198 $liste = $this->fetch_array($resql);
1199 $basedir = $liste['Value
'];
1200 $fullpathofimport = $basedir.(preg_match('/\/$/
', $basedir) ? '' : '/
').'bin/mysql
';
1202 return $fullpathofimport;
1211 public function getServerParametersValues($filter = '
')
1215 $sql = 'SHOW VARIABLES
';
1217 $sql .= " LIKE '".$this->escape($filter)."'";
1219 $resql = $this->query($sql);
1221 while ($obj = $this->fetch_object($resql)) {
1222 $result[$obj->Variable_name] = $obj->Value;
1235 public function getServerStatusValues($filter = '
')
1239 $sql = 'SHOW STATUS
';
1241 $sql .= " LIKE '".$this->escape($filter)."'";
1243 $resql = $this->query($sql);
1245 while ($obj = $this->fetch_object($resql)) {
1246 $result[$obj->Variable_name] = $obj->Value;
1257class mysqliDoli extends mysqli
1270 public function __construct($host, $user, $pass, $name, $port = 0, $socket = "")
1274 if (strpos($host, 'ssl:
1275 $host = substr($host, 6);
1276 parent::options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT,
false);
1277 parent::ssl_set(
null,
null,
"",
null,
null);
1278 $flags = MYSQLI_CLIENT_SSL;
1280 parent::real_connect($host, $user, $pass, $name, $port, $socket, $flags);
Class to manage Dolibarr database access.
lastqueryerror()
Return last query in error.
lasterror()
Return last error label.
lasterrno()
Return last error code.
lastquery()
Return last request executed with query()
Class to manage Dolibarr database access for a MySQL database using the MySQLi extension.
fetch_array($resultset)
Return datas as an array.
__construct($type, $host, $user, $pass, $name='', $port=0)
Constructor.
free($resultset=null)
Libere le dernier resultset utilise sur cette connexion.
escapeforlike($stringtoencode)
Escape a string to insert data into a like.
num_rows($resultset)
Return number of lines for result of a SELECT.
const VERSIONMIN
Version min database.
error()
Return description of last error.
escape($stringtoencode)
Escape a string to insert data.
getVersion()
Return version of database server.
fetch_object($resultset)
Returns the current line (as an object) for the resultset cursor.
encrypt($fieldorvalue, $withQuotes=1)
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple ...
convertSQLFromMysql($line, $type='ddl')
Convert a SQL request in Mysql syntax to native syntax.
affected_rows($resultset)
Return the number of lines in the result of a request INSERT, DELETE or UPDATE.
select_db($database)
Select a database.
decrypt($value)
Decrypt sensitive data in database.
fetch_row($resultset)
Return datas as an array.
last_insert_id($tab, $fieldid='rowid')
Get last ID after an insert INSERT.
const LABEL
Database label.
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
hintindex($nameofindex)
Return SQL string to force an index.
connect($host, $login, $passwd, $name, $port=0)
Connect to server.
errno()
Return generic error code of last operation.
getDriverInfo()
Return version of database client driver.
close()
Close database connexion.
Class to make SSL connection.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type