28 require_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->dolibarr_main_db_character_set) ?
'utf8' : $conf->db->dolibarr_main_db_character_set;
116 if (preg_match(
'/latin1/', $clientmustbe)) {
117 $clientmustbe =
'utf8';
120 if ($this->
db->character_set_name() != $clientmustbe) {
121 $this->
db->set_charset($clientmustbe);
123 $collation = $conf->db->dolibarr_main_db_collation;
124 if (preg_match(
'/latin1/', $collation)) {
125 $collation =
'utf8_unicode_ci';
128 if (!preg_match(
'/general/', $collation)) {
129 $this->
db->query(
"SET collation_connection = ".$collation);
133 $this->database_selected =
false;
134 $this->database_name =
'';
137 dol_syslog(get_class($this).
"::DoliDBMysqli : Select_db error ".$this->
error, LOG_ERR);
141 $this->database_selected =
false;
143 if ($this->connected) {
145 $clientmustbe = empty($conf->db->dolibarr_main_db_character_set) ?
'utf8' : $conf->db->dolibarr_main_db_character_set;
146 if (preg_match(
'/latin1/', $clientmustbe)) {
147 $clientmustbe =
'utf8';
149 if (preg_match(
'/utf8mb4/', $clientmustbe)) {
150 $clientmustbe =
'utf8';
153 if ($this->
db->character_set_name() != $clientmustbe) {
154 $this->
db->set_charset($clientmustbe);
156 $collation = $conf->db->dolibarr_main_db_collation;
157 if (preg_match(
'/latin1/', $collation)) {
158 $collation =
'utf8_unicode_ci';
160 if (preg_match(
'/utf8mb4/', $collation)) {
161 $collation =
'utf8_unicode_ci';
164 if (!preg_match(
'/general/', $collation)) {
165 $this->
db->query(
"SET collation_connection = ".$collation);
181 return " FORCE INDEX(".preg_replace(
'/[^a-z0-9_]/',
'', $nameofindex).
")";
208 dol_syslog(get_class($this).
"::select_db database=".$database, LOG_DEBUG);
211 $result = $this->
db->select_db($database);
230 public function connect($host, $login, $passwd, $name, $port = 0)
232 dol_syslog(get_class($this).
"::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name", LOG_DEBUG);
241 $tmp =
new mysqli($host, $login, $passwd, $name, $port);
243 dol_syslog(get_class($this).
"::connect failed", LOG_DEBUG);
255 return $this->
db->server_info;
265 return $this->
db->client_info;
278 if ($this->transaction_opened > 0) {
279 dol_syslog(get_class($this).
"::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR);
281 $this->connected =
false;
282 return $this->
db->close();
299 public function query($query, $usesavepoint = 0,
$type =
'auto', $result_mode = 0)
301 global $conf, $dolibarr_main_db_readonly;
303 $query = trim($query);
305 if (!in_array($query, array(
'BEGIN',
'COMMIT',
'ROLLBACK'))) {
306 $SYSLOG_SQL_LIMIT = 10000;
307 dol_syslog(
'sql='.substr($query, 0, $SYSLOG_SQL_LIMIT), LOG_DEBUG);
313 if (!empty($dolibarr_main_db_readonly)) {
314 if (preg_match(
'/^(INSERT|UPDATE|REPLACE|DELETE|CREATE|ALTER|TRUNCATE|DROP)/i', $query)) {
315 $this->
lasterror =
'Application in read-only mode';
323 if (!$this->database_name) {
325 $ret = $this->
db->query($query, $result_mode);
327 $ret = $this->
db->query($query, $result_mode);
330 dol_syslog(get_class($this).
"::query Exception in query instead of returning an error: ".$e->getMessage(), LOG_ERR);
334 if (!preg_match(
"/^COMMIT/i", $query) && !preg_match(
"/^ROLLBACK/i", $query)) {
341 if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) {
342 dol_syslog(get_class($this).
"::query SQL Error query: ".$query, LOG_ERR);
344 dol_syslog(get_class($this).
"::query SQL Error message: ".$this->
lasterrno.
" ".$this->lasterror, LOG_ERR);
348 $this->_results = $ret;
365 if (!is_object($resultset)) {
366 $resultset = $this->_results;
368 return $resultset->fetch_object();
383 if (!is_object($resultset)) {
384 $resultset = $this->_results;
386 return $resultset->fetch_array();
400 if (!is_bool($resultset)) {
401 if (!is_object($resultset)) {
402 $resultset = $this->_results;
404 return $resultset->fetch_row();
423 if (!is_object($resultset)) {
424 $resultset = $this->_results;
426 return isset($resultset->num_rows) ? $resultset->num_rows : 0;
441 if (!is_object($resultset)) {
442 $resultset = $this->_results;
446 return $this->
db->affected_rows;
456 public function free($resultset =
null)
459 if (!is_object($resultset)) {
460 $resultset = $this->_results;
463 if (is_object($resultset)) {
464 $resultset->free_result();
476 return $this->
db->real_escape_string((
string) $stringtoencode);
487 return str_replace(array(
'_',
'\\',
'%'), array(
'\_',
'\\\\',
'\%'), (
string) $stringtoencode);
497 if (!$this->connected) {
499 return 'DB_ERROR_FAILED_TO_CONNECT';
502 $errorcode_map = array(
503 1004 =>
'DB_ERROR_CANNOT_CREATE',
504 1005 =>
'DB_ERROR_CANNOT_CREATE',
505 1006 =>
'DB_ERROR_CANNOT_CREATE',
506 1007 =>
'DB_ERROR_ALREADY_EXISTS',
507 1008 =>
'DB_ERROR_CANNOT_DROP',
508 1022 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
509 1025 =>
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
510 1044 =>
'DB_ERROR_ACCESSDENIED',
511 1046 =>
'DB_ERROR_NODBSELECTED',
512 1048 =>
'DB_ERROR_CONSTRAINT',
513 1050 =>
'DB_ERROR_TABLE_ALREADY_EXISTS',
514 1051 =>
'DB_ERROR_NOSUCHTABLE',
515 1054 =>
'DB_ERROR_NOSUCHFIELD',
516 1060 =>
'DB_ERROR_COLUMN_ALREADY_EXISTS',
517 1061 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
518 1062 =>
'DB_ERROR_RECORD_ALREADY_EXISTS',
519 1064 =>
'DB_ERROR_SYNTAX',
520 1068 =>
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
521 1075 =>
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
522 1091 =>
'DB_ERROR_NOSUCHFIELD',
523 1100 =>
'DB_ERROR_NOT_LOCKED',
524 1136 =>
'DB_ERROR_VALUE_COUNT_ON_ROW',
525 1146 =>
'DB_ERROR_NOSUCHTABLE',
526 1215 =>
'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT',
527 1216 =>
'DB_ERROR_NO_PARENT',
528 1217 =>
'DB_ERROR_CHILD_EXISTS',
529 1396 =>
'DB_ERROR_USER_ALREADY_EXISTS',
530 1451 =>
'DB_ERROR_CHILD_EXISTS',
531 1826 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
534 if (isset($errorcode_map[$this->
db->errno])) {
535 return $errorcode_map[$this->
db->errno];
537 $errno = $this->
db->errno;
538 return ($errno ?
'DB_ERROR_'.$errno :
'0');
549 if (!$this->connected) {
551 return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions';
553 return $this->
db->error;
568 return $this->
db->insert_id;
579 public function encrypt($fieldorvalue, $withQuotes = 1)
584 $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0);
587 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey :
'');
589 $escapedstringwithquotes = ($withQuotes ?
"'" :
"").$this->
escape($fieldorvalue).($withQuotes ?
"'" :
"");
591 if ($cryptType && !empty($cryptKey)) {
592 if ($cryptType == 2) {
593 $escapedstringwithquotes =
"AES_ENCRYPT(".$escapedstringwithquotes.
", '".$this->
escape($cryptKey).
"')";
594 } elseif ($cryptType == 1) {
595 $escapedstringwithquotes =
"DES_ENCRYPT(".$escapedstringwithquotes.
", '".$this->
escape($cryptKey).
"')";
599 return $escapedstringwithquotes;
613 $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0);
616 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey :
'');
620 if ($cryptType && !empty($cryptKey)) {
621 if ($cryptType == 2) {
622 $return =
'AES_DECRYPT('.$value.
',\''.$cryptKey.
'\')
';
623 } elseif ($cryptType == 1) {
624 $return = 'DES_DECRYPT(
'.$value.',\
''.$cryptKey.
'\')
';
632 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
638 public function DDLGetConnectId()
641 $resql = $this->query('SELECT CONNECTION_ID()
');
643 $row = $this->fetch_row($resql);
650 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
662 public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
665 if (empty($charset)) {
666 $charset = $this->forcecharset;
668 if (empty($collation)) {
669 $collation = $this->forcecollate;
672 // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
673 $sql = "CREATE DATABASE `".$this->escape($database)."`";
674 $sql .= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`";
676 dol_syslog($sql, LOG_DEBUG);
677 $ret = $this->query($sql);
679 // We try again for compatibility with Mysql < 4.1.1
680 $sql = "CREATE DATABASE `".$this->escape($database)."`";
681 dol_syslog($sql, LOG_DEBUG);
682 $ret = $this->query($sql);
687 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
695 public function DDLListTables($database, $table = '')
698 $listtables = array();
702 $tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i
', '', $table);
704 $like = "LIKE '".$this->escape($tmptable)."'";
706 $tmpdatabase = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $database);
708 $sql = "SHOW TABLES FROM ".$tmpdatabase." ".$like.";";
710 $result = $this->query($sql);
712 while ($row = $this->fetch_row($result)) {
713 $listtables[] = $row[0];
719 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
726 public function DDLInfoTable($table)
729 $infotables = array();
731 $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $table);
733 $sql = "SHOW FULL COLUMNS FROM ".$tmptable.";";
735 dol_syslog($sql, LOG_DEBUG);
736 $result = $this->query($sql);
738 while ($row = $this->fetch_row($result)) {
739 $infotables[] = $row;
745 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
758 public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null)
761 // FIXME: $fulltext_keys parameter is unused
764 $sqluq = $sqlk = array();
766 // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra
767 // ex. : $fields['rowid'] = array('type'=>'int','value
'=>'11
','null'=>'not
null','extra
'=> 'auto_increment
');
768 $sql = "CREATE TABLE ".$table."(";
770 $sqlfields = array();
771 foreach ($fields as $field_name => $field_desc) {
772 $sqlfields[$i] = $field_name." ";
773 $sqlfields[$i] .= $field_desc['type'];
774 if (preg_match("/^[^\s]/i", $field_desc['value
'])) {
775 $sqlfields[$i] .= "(".$field_desc['value
'].")";
777 if (preg_match("/^[^\s]/i", $field_desc['attribute
'])) {
778 $sqlfields[$i] .= " ".$field_desc['attribute
'];
780 if (preg_match("/^[^\s]/i", $field_desc['default'])) {
781 if ((preg_match("/null/i", $field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i", $field_desc['default']))) {
782 $sqlfields[$i] .= " default ".$field_desc['default'];
784 $sqlfields[$i] .= " default '".$this->escape($field_desc['default'])."'";
787 if (preg_match("/^[^\s]/i", $field_desc['null'])) {
788 $sqlfields[$i] .= " ".$field_desc['null'];
790 if (preg_match("/^[^\s]/i", $field_desc['extra
'])) {
791 $sqlfields[$i] .= " ".$field_desc['extra
'];
795 if ($primary_key != "") {
796 $pk = "primary key(".$primary_key.")";
799 if (is_array($unique_keys)) {
801 foreach ($unique_keys as $key => $value) {
802 $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$this->escape($value)."')";
806 if (is_array($keys)) {
808 foreach ($keys as $key => $value) {
809 $sqlk[$i] = "KEY ".$key." (".$value.")";
813 $sql .= implode(',
', $sqlfields);
814 if ($primary_key != "") {
817 if ($unique_keys != "") {
818 $sql .= ",".implode(',
', $sqluq);
820 if (is_array($keys)) {
821 $sql .= ",".implode(',
', $sqlk);
823 $sql .= ") engine=".$type;
825 if (!$this->query($sql)) {
832 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
839 public function DDLDropTable($table)
842 $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $table);
844 $sql = "DROP TABLE ".$tmptable;
846 if (!$this->query($sql)) {
853 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
861 public function DDLDescTable($table, $field = "")
864 $sql = "DESC ".$table." ".$field;
866 dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG);
867 $this->_results = $this->query($sql);
868 return $this->_results;
871 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
881 public function DDLAddField($table, $field_name, $field_desc, $field_position = "")
884 // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
885 // ex. : $field_desc = array('type'=>'int','value
'=>'11
','null'=>'not
null','extra
'=> 'auto_increment
');
886 $sql = "ALTER TABLE ".$table." ADD ".$field_name." ";
887 $sql .= $field_desc['type'];
888 if (preg_match("/^[^\s]/i", $field_desc['value
'])) {
889 if (!in_array($field_desc['type'], array('date
', 'datetime
')) && $field_desc['value
']) {
890 $sql .= "(".$field_desc['value
'].")";
893 if (isset($field_desc['attribute
']) && preg_match("/^[^\s]/i", $field_desc['attribute
'])) {
894 $sql .= " ".$field_desc['attribute
'];
896 if (isset($field_desc['null']) && preg_match("/^[^\s]/i", $field_desc['null'])) {
897 $sql .= " ".$field_desc['null'];
899 if (isset($field_desc['default']) && preg_match("/^[^\s]/i", $field_desc['default'])) {
900 if (preg_match("/null/i", $field_desc['default'])) {
901 $sql .= " default ".$field_desc['default'];
903 $sql .= " default '".$this->escape($field_desc['default'])."'";
906 if (isset($field_desc['extra
']) && preg_match("/^[^\s]/i", $field_desc['extra
'])) {
907 $sql .= " ".$field_desc['extra
'];
909 $sql .= " ".$field_position;
911 dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG);
912 if ($this->query($sql)) {
918 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
927 public function DDLUpdateField($table, $field_name, $field_desc)
930 $sql = "ALTER TABLE ".$table;
931 $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type'];
932 if (in_array($field_desc['type'], array('double', 'tinyint
', 'int', 'varchar
')) && $field_desc['value
']) {
933 $sql .= "(".$field_desc['value
'].")";
935 if ($field_desc['null'] == 'not
null' || $field_desc['null'] == 'NOT NULL
') {
936 // 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
937 if ($field_desc['type'] == 'varchar
' || $field_desc['type'] == 'text
') {
938 $sqlbis = "UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
939 $this->query($sqlbis);
940 } elseif ($field_desc['type'] == 'tinyint
' || $field_desc['type'] == 'int') {
941 $sqlbis = "UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
942 $this->query($sqlbis);
948 if ($field_desc['default'] != '') {
949 if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint
' || $field_desc['type'] == 'int') {
950 $sql .= " DEFAULT ".$this->escape($field_desc['default']);
951 } elseif ($field_desc['type'] != 'text
') {
952 $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
956 dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG);
957 if (!$this->query($sql)) {
964 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
972 public function DDLDropField($table, $field_name)
975 $tmp_field_name = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $field_name);
977 $sql = "ALTER TABLE ".$table." DROP COLUMN `".$tmp_field_name."`";
978 if ($this->query($sql)) {
981 $this->error = $this->lasterror();
986 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
996 public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
999 $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
1000 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1001 $resql = $this->query($sql);
1003 if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS
') {
1006 // If user already exists, we continue to set permissions
1007 dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
1011 // Redo with localhost forced (sometimes user is created on %)
1012 $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'localhost
' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
1013 $resql = $this->query($sql);
1015 $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."'";
1016 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1017 $resql = $this->query($sql);
1019 $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)."'";
1023 $sql = "FLUSH Privileges";
1025 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG);
1026 $resql = $this->query($sql);
1041 public function getDefaultCharacterSetDatabase()
1043 $resql = $this->query('SHOW VARIABLES LIKE \
'character_set_database\'');
1046 return $this->forcecharset;
1049 $tmpval = $liste[
'Value'];
1066 $liste[$i][
'charset'] = $obj->Charset;
1067 $liste[$i][
'description'] = $obj->Description;
1086 $resql = $this->
query(
'SHOW VARIABLES LIKE \'collation_database\'');
1089 return $this->forcecollate;
1092 $tmpval = $liste[
'Value'];
1109 $liste[$i][
'collation'] = $obj->Collation;
1127 $fullpathofdump =
'/pathtomysqldump/mysqldump';
1129 $resql = $this->
query(
'SHOW VARIABLES LIKE \'basedir\'');
1132 $basedir = $liste[
'Value'];
1133 $fullpathofdump = $basedir.(preg_match(
'/\/$/', $basedir) ?
'' :
'/').
'bin/mysqldump';
1135 return $fullpathofdump;
1145 $fullpathofimport =
'/pathtomysql/mysql';
1147 $resql = $this->
query(
'SHOW VARIABLES LIKE \'basedir\'');
1150 $basedir = $liste[
'Value'];
1151 $fullpathofimport = $basedir.(preg_match(
'/\/$/', $basedir) ?
'' :
'/').
'bin/mysql';
1153 return $fullpathofimport;
1166 $sql =
'SHOW VARIABLES';
1168 $sql .=
" LIKE '".$this->escape($filter).
"'";
1173 $result[$obj->Variable_name] = $obj->Value;
1190 $sql =
'SHOW STATUS';
1192 $sql .=
" LIKE '".$this->escape($filter).
"'";
1197 $result[$obj->Variable_name] = $obj->Value;
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.
getServerStatusValues($filter='')
Return value of server status (current indicators on memory, cache...)
num_rows($resultset)
Return number of lines for result of a SELECT.
getServerParametersValues($filter='')
Return value of server parameters.
const VERSIONMIN
Version min database.
error()
Return description of last error.
static convertSQLFromMysql($line, $type='ddl')
Convert a SQL request in Mysql syntax to native syntax.
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 ...
affected_rows($resultset)
Return the number of lines in the result of a request INSERT, DELETE or UPDATE.
getDefaultCollationDatabase()
Return collation used in current database.
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.
getPathOfRestore()
Return full path of restore program.
getPathOfDump()
Return full path of dump program.
connect($host, $login, $passwd, $name, $port=0)
Connect to server.
errno()
Return generic error code of last operation.
getListOfCollation()
Return list of available collation that can be used for database.
getDriverInfo()
Return version of database client driver.
getListOfCharacterSet()
Return list of available charset that can be used to store data in database.
close()
Close database connexion.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db
API class for accounts.