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->character_set) ?
'utf8' : $conf->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->character_set) ?
'utf8' : $conf->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);
238 if (!class_exists(
'mysqli')) {
241 if (strpos($host,
'ssl://') === 0) {
242 $tmp =
new mysqliDoli($host, $login, $passwd, $name, $port);
244 $tmp =
new mysqli($host, $login, $passwd, $name, $port);
247 dol_syslog(get_class($this).
"::connect failed", LOG_DEBUG);
259 return $this->db->server_info;
269 return $this->db->client_info;
282 if ($this->transaction_opened > 0) {
283 dol_syslog(get_class($this).
"::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR);
285 $this->connected =
false;
286 return $this->db->close();
303 public function query($query, $usesavepoint = 0,
$type =
'auto', $result_mode = 0)
305 global $conf, $dolibarr_main_db_readonly;
307 $query = trim($query);
309 if (!in_array($query, array(
'BEGIN',
'COMMIT',
'ROLLBACK'))) {
310 $SYSLOG_SQL_LIMIT = 10000;
311 dol_syslog(
'sql='.substr($query, 0, $SYSLOG_SQL_LIMIT), LOG_DEBUG);
317 if (!empty($dolibarr_main_db_readonly)) {
318 if (preg_match(
'/^(INSERT|UPDATE|REPLACE|DELETE|CREATE|ALTER|TRUNCATE|DROP)/i', $query)) {
319 $this->
lasterror =
'Application in read-only mode';
327 if (!$this->database_name) {
329 $ret = $this->db->query($query, $result_mode);
331 $ret = $this->db->query($query, $result_mode);
334 dol_syslog(get_class($this).
"::query Exception in query instead of returning an error: ".$e->getMessage(), LOG_ERR);
338 if (!preg_match(
"/^COMMIT/i", $query) && !preg_match(
"/^ROLLBACK/i", $query)) {
346 dol_syslog(get_class($this).
"::query SQL Error query: ".$query, LOG_ERR);
348 dol_syslog(get_class($this).
"::query SQL Error message: ".$this->
lasterrno.
" ".$this->lasterror, LOG_ERR);
352 $this->_results = $ret;
369 if (!is_object($resultset)) {
370 $resultset = $this->_results;
372 return $resultset->fetch_object();
387 if (!is_object($resultset)) {
388 $resultset = $this->_results;
390 return $resultset->fetch_array();
404 if (!is_bool($resultset)) {
405 if (!is_object($resultset)) {
406 $resultset = $this->_results;
408 return $resultset->fetch_row();
427 if (!is_object($resultset)) {
428 $resultset = $this->_results;
430 return isset($resultset->num_rows) ? $resultset->num_rows : 0;
445 if (!is_object($resultset)) {
446 $resultset = $this->_results;
450 return $this->db->affected_rows;
460 public function free($resultset =
null)
463 if (!is_object($resultset)) {
464 $resultset = $this->_results;
467 if (is_object($resultset)) {
468 $resultset->free_result();
480 return $this->db->real_escape_string((
string) $stringtoencode);
491 return str_replace(array(
'\\',
'_',
'%'), array(
'\\\\',
'\_',
'\%'), (
string) $stringtoencode);
501 if (!$this->connected) {
503 return 'DB_ERROR_FAILED_TO_CONNECT';
506 $errorcode_map = array(
507 1004 =>
'DB_ERROR_CANNOT_CREATE',
508 1005 =>
'DB_ERROR_CANNOT_CREATE',
509 1006 =>
'DB_ERROR_CANNOT_CREATE',
510 1007 =>
'DB_ERROR_ALREADY_EXISTS',
511 1008 =>
'DB_ERROR_CANNOT_DROP',
512 1022 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
513 1025 =>
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
514 1044 =>
'DB_ERROR_ACCESSDENIED',
515 1046 =>
'DB_ERROR_NODBSELECTED',
516 1048 =>
'DB_ERROR_CONSTRAINT',
517 1050 =>
'DB_ERROR_TABLE_ALREADY_EXISTS',
518 1051 =>
'DB_ERROR_NOSUCHTABLE',
519 1054 =>
'DB_ERROR_NOSUCHFIELD',
520 1060 =>
'DB_ERROR_COLUMN_ALREADY_EXISTS',
521 1061 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
522 1062 =>
'DB_ERROR_RECORD_ALREADY_EXISTS',
523 1064 =>
'DB_ERROR_SYNTAX',
524 1068 =>
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
525 1075 =>
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
526 1091 =>
'DB_ERROR_NOSUCHFIELD',
527 1100 =>
'DB_ERROR_NOT_LOCKED',
528 1136 =>
'DB_ERROR_VALUE_COUNT_ON_ROW',
529 1146 =>
'DB_ERROR_NOSUCHTABLE',
530 1215 =>
'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT',
531 1216 =>
'DB_ERROR_NO_PARENT',
532 1217 =>
'DB_ERROR_CHILD_EXISTS',
533 1396 =>
'DB_ERROR_USER_ALREADY_EXISTS',
534 1451 =>
'DB_ERROR_CHILD_EXISTS',
535 1826 =>
'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
538 if (isset($errorcode_map[$this->db->errno])) {
539 return $errorcode_map[$this->db->errno];
541 $errno = $this->db->errno;
542 return ($errno ?
'DB_ERROR_'.$errno :
'0');
553 if (!$this->connected) {
555 return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions';
557 return $this->db->error;
572 return $this->db->insert_id;
583 public function encrypt($fieldorvalue, $withQuotes = 1)
588 $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0);
591 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey :
'');
593 $escapedstringwithquotes = ($withQuotes ?
"'" :
"").$this->
escape($fieldorvalue).($withQuotes ?
"'" :
"");
595 if ($cryptType && !empty($cryptKey)) {
596 if ($cryptType == 2) {
597 $escapedstringwithquotes =
"AES_ENCRYPT(".$escapedstringwithquotes.
", '".$this->
escape($cryptKey).
"')";
598 } elseif ($cryptType == 1) {
599 $escapedstringwithquotes =
"DES_ENCRYPT(".$escapedstringwithquotes.
", '".$this->
escape($cryptKey).
"')";
603 return $escapedstringwithquotes;
617 $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0);
620 $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey :
'');
624 if ($cryptType && !empty($cryptKey)) {
625 if ($cryptType == 2) {
626 $return =
'AES_DECRYPT('.$value.
',\''.$cryptKey.
'\')
';
627 } elseif ($cryptType == 1) {
628 $return = 'DES_DECRYPT(
'.$value.',\
''.$cryptKey.
'\')
';
636 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
642 public function DDLGetConnectId()
645 $resql = $this->query('SELECT CONNECTION_ID()
');
647 $row = $this->fetch_row($resql);
654 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
666 public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
669 if (empty($charset)) {
670 $charset = $this->forcecharset;
672 if (empty($collation)) {
673 $collation = $this->forcecollate;
676 // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
677 $sql = "CREATE DATABASE `".$this->escape($database)."`";
678 $sql .= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`";
680 dol_syslog($sql, LOG_DEBUG);
681 $ret = $this->query($sql);
683 // We try again for compatibility with Mysql < 4.1.1
684 $sql = "CREATE DATABASE `".$this->escape($database)."`";
685 dol_syslog($sql, LOG_DEBUG);
686 $ret = $this->query($sql);
691 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
699 public function DDLListTables($database, $table = '')
702 $listtables = array();
706 $tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i
', '', $table);
708 $like = "LIKE '".$this->escape($tmptable)."'";
710 $tmpdatabase = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $database);
712 $sql = "SHOW TABLES FROM `".$tmpdatabase."` ".$like.";";
714 $result = $this->query($sql);
716 while ($row = $this->fetch_row($result)) {
717 $listtables[] = $row[0];
723 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
731 public function DDLListTablesFull($database, $table = '')
734 $listtables = array();
738 $tmptable = preg_replace('/[^a-z0-9\.\-\_%]/i
', '', $table);
740 $like = "LIKE '".$this->escape($tmptable)."'";
742 $tmpdatabase = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $database);
744 $sql = "SHOW FULL TABLES FROM `".$tmpdatabase."` ".$like.";";
746 $result = $this->query($sql);
748 while ($row = $this->fetch_row($result)) {
749 $listtables[] = $row;
755 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
762 public function DDLInfoTable($table)
765 $infotables = array();
767 $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $table);
769 $sql = "SHOW FULL COLUMNS FROM ".$tmptable.";";
771 dol_syslog($sql, LOG_DEBUG);
772 $result = $this->query($sql);
774 while ($row = $this->fetch_row($result)) {
775 $infotables[] = $row;
781 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
794 public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null)
797 // FIXME: $fulltext_keys parameter is unused
800 $sqluq = $sqlk = array();
802 // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra
803 // ex. : $fields['rowid'] = array('type'=>'int','value
'=>'11
','null'=>'not
null','extra
'=> 'auto_increment
');
804 $sql = "CREATE TABLE ".$table."(";
806 $sqlfields = array();
807 foreach ($fields as $field_name => $field_desc) {
808 $sqlfields[$i] = $field_name." ";
809 $sqlfields[$i] .= $field_desc['type'];
810 if (preg_match("/^[^\s]/i", $field_desc['value
'])) {
811 $sqlfields[$i] .= "(".$field_desc['value
'].")";
813 if (preg_match("/^[^\s]/i", $field_desc['attribute
'])) {
814 $sqlfields[$i] .= " ".$field_desc['attribute
'];
816 if (preg_match("/^[^\s]/i", $field_desc['default'])) {
817 if ((preg_match("/null/i", $field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i", $field_desc['default']))) {
818 $sqlfields[$i] .= " default ".$field_desc['default'];
820 $sqlfields[$i] .= " default '".$this->escape($field_desc['default'])."'";
823 if (preg_match("/^[^\s]/i", $field_desc['null'])) {
824 $sqlfields[$i] .= " ".$field_desc['null'];
826 if (preg_match("/^[^\s]/i", $field_desc['extra
'])) {
827 $sqlfields[$i] .= " ".$field_desc['extra
'];
831 if ($primary_key != "") {
832 $pk = "primary key(".$primary_key.")";
835 if (is_array($unique_keys)) {
837 foreach ($unique_keys as $key => $value) {
838 $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$this->escape($value)."')";
842 if (is_array($keys)) {
844 foreach ($keys as $key => $value) {
845 $sqlk[$i] = "KEY ".$key." (".$value.")";
849 $sql .= implode(',
', $sqlfields);
850 if ($primary_key != "") {
853 if ($unique_keys != "") {
854 $sql .= ",".implode(',
', $sqluq);
856 if (is_array($keys)) {
857 $sql .= ",".implode(',
', $sqlk);
859 $sql .= ") engine=".$type;
861 if (!$this->query($sql)) {
868 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
875 public function DDLDropTable($table)
878 $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $table);
880 $sql = "DROP TABLE ".$tmptable;
882 if (!$this->query($sql)) {
889 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
897 public function DDLDescTable($table, $field = "")
900 $sql = "DESC ".$table." ".$field;
902 dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG);
903 $this->_results = $this->query($sql);
904 return $this->_results;
907 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
917 public function DDLAddField($table, $field_name, $field_desc, $field_position = "")
920 // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
921 // ex. : $field_desc = array('type'=>'int','value
'=>'11
','null'=>'not
null','extra
'=> 'auto_increment
');
922 $sql = "ALTER TABLE ".$table." ADD ".$field_name." ";
923 $sql .= $field_desc['type'];
924 if (preg_match("/^[^\s]/i", $field_desc['value
'])) {
925 if (!in_array($field_desc['type'], array('date
', 'datetime
')) && $field_desc['value
']) {
926 $sql .= "(".$field_desc['value
'].")";
929 if (isset($field_desc['attribute
']) && preg_match("/^[^\s]/i", $field_desc['attribute
'])) {
930 $sql .= " ".$field_desc['attribute
'];
932 if (isset($field_desc['null']) && preg_match("/^[^\s]/i", $field_desc['null'])) {
933 $sql .= " ".$field_desc['null'];
935 if (isset($field_desc['default']) && preg_match("/^[^\s]/i", $field_desc['default'])) {
936 if (preg_match("/null/i", $field_desc['default'])) {
937 $sql .= " default ".$field_desc['default'];
939 $sql .= " default '".$this->escape($field_desc['default'])."'";
942 if (isset($field_desc['extra
']) && preg_match("/^[^\s]/i", $field_desc['extra
'])) {
943 $sql .= " ".$field_desc['extra
'];
945 $sql .= " ".$field_position;
947 dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG);
948 if ($this->query($sql)) {
954 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
963 public function DDLUpdateField($table, $field_name, $field_desc)
966 $sql = "ALTER TABLE ".$table;
967 $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type'];
968 if (in_array($field_desc['type'], array('double', 'tinyint
', 'int', 'varchar
')) && $field_desc['value
']) {
969 $sql .= "(".$field_desc['value
'].")";
971 if ($field_desc['null'] == 'not
null' || $field_desc['null'] == 'NOT NULL
') {
972 // 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
973 if ($field_desc['type'] == 'varchar
' || $field_desc['type'] == 'text
') {
974 $sqlbis = "UPDATE ".$table." SET ".$field_name." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
975 $this->query($sqlbis);
976 } elseif ($field_desc['type'] == 'tinyint
' || $field_desc['type'] == 'int') {
977 $sqlbis = "UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape(isset($field_desc['default']) ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
978 $this->query($sqlbis);
984 if (isset($field_desc['default']) && $field_desc['default'] != '') {
985 if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint
' || $field_desc['type'] == 'int') {
986 $sql .= " DEFAULT ".$this->escape($field_desc['default']);
987 } elseif ($field_desc['type'] != 'text
') {
988 $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
992 dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG);
993 if (!$this->query($sql)) {
1000 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1008 public function DDLDropField($table, $field_name)
1011 $tmp_field_name = preg_replace('/[^a-z0-9\.\-\_]/i
', '', $field_name);
1013 $sql = "ALTER TABLE ".$table." DROP COLUMN `".$tmp_field_name."`";
1014 if ($this->query($sql)) {
1017 $this->error = $this->lasterror();
1022 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1032 public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
1035 $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
1036 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1037 $resql = $this->query($sql);
1039 if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS
') {
1042 // If user already exists, we continue to set permissions
1043 dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
1047 // Redo with localhost forced (sometimes user is created on %)
1048 $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'localhost
' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
1049 $resql = $this->query($sql);
1051 $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."'";
1052 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1053 $resql = $this->query($sql);
1055 $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)."'";
1059 $sql = "FLUSH Privileges";
1061 dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG);
1062 $resql = $this->query($sql);
1077 public function getDefaultCharacterSetDatabase()
1079 $resql = $this->query('SHOW VARIABLES LIKE \
'character_set_database\'');
1082 return $this->forcecharset;
1085 $tmpval = $liste[
'Value'];
1097 $resql = $this->
query(
'SHOW CHARSET');
1102 $liste[$i][
'charset'] = $obj->Charset;
1103 $liste[$i][
'description'] = $obj->Description;
1106 $this->
free($resql);
1122 $resql = $this->
query(
'SHOW VARIABLES LIKE \'collation_database\'');
1125 return $this->forcecollate;
1128 $tmpval = $liste[
'Value'];
1140 $resql = $this->
query(
'SHOW COLLATION');
1145 $liste[$i][
'collation'] = $obj->Collation;
1148 $this->
free($resql);
1163 $fullpathofdump =
'/pathtomysqldump/mysqldump';
1165 $resql = $this->
query(
'SHOW VARIABLES LIKE \'basedir\'');
1168 $basedir = $liste[
'Value'];
1169 $fullpathofdump = $basedir.(preg_match(
'/\/$/', $basedir) ?
'' :
'/').
'bin/mysqldump';
1171 return $fullpathofdump;
1181 $fullpathofimport =
'/pathtomysql/mysql';
1183 $resql = $this->
query(
'SHOW VARIABLES LIKE \'basedir\'');
1186 $basedir = $liste[
'Value'];
1187 $fullpathofimport = $basedir.(preg_match(
'/\/$/', $basedir) ?
'' :
'/').
'bin/mysql';
1189 return $fullpathofimport;
1202 $sql =
'SHOW VARIABLES';
1204 $sql .=
" LIKE '".$this->escape($filter).
"'";
1209 $result[$obj->Variable_name] = $obj->Value;
1226 $sql =
'SHOW STATUS';
1228 $sql .=
" LIKE '".$this->escape($filter).
"'";
1233 $result[$obj->Variable_name] = $obj->Value;
1257 public function __construct($host, $user, $pass, $name, $port = 0, $socket =
"")
1261 if (strpos($host,
'ssl://') === 0) {
1262 $host = substr($host, 6);
1263 parent::options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT,
false);
1264 parent::ssl_set(
null,
null,
"",
null,
null);
1265 $flags = MYSQLI_CLIENT_SSL;
1267 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.
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.
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.
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.
Class to make SSL connection.
__construct($host, $user, $pass, $name, $port=0, $socket="")
Constructor.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
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 dolibarr global constant int value.
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