26require_once DOL_DOCUMENT_ROOT.
'/core/db/DoliDB.class.php';
50 protected $startMemory;
72 $this->
type = $this->db->type;
73 $this->queries = array();
84 public function ifsql($test, $resok, $resko)
86 return $this->db->ifsql($test, $resok, $resko);
99 return $this->db->regexpsql($subject, $pattern, $sqlstring = 0);
112 return $this->db->fetch_row($resultset);
123 public function idate($param, $gm =
'tzserver')
125 return $this->db->idate($param, $gm);
135 return $this->db->lasterrno();
144 public function begin($textinlog =
'')
146 return $this->db->begin($textinlog);
160 public function DDLCreateDb($database, $charset =
'', $collation =
'', $owner =
'')
162 return $this->db->DDLCreateDb($database, $charset, $collation, $owner);
172 return $this->db->getVersionArray();
184 return $this->db->convertSQLFromMysql($line);
198 return $this->db->affected_rows($resultset);
208 return $this->db->error();
220 return $this->db->DDLListTables($database, $table);
232 return $this->db->DDLListTablesFull($database, $table);
242 return $this->db->lastquery();
252 public function order($sortfield =
null, $sortorder =
null)
254 return $this->db->order($sortfield, $sortorder);
265 return $this->db->decrypt($value);
278 return $this->db->fetch_array($resultset);
288 return $this->db->lasterror();
299 return $this->db->escape($stringtoencode);
310 return $this->db->escapeforlike($stringtoencode);
324 return $this->db->last_insert_id($tab, $fieldid);
334 return $this->db->getPathOfRestore();
345 return $this->db->rollback($log);
358 public function query($query, $usesavepoint = 0, $type =
'auto', $result_mode = 0)
362 $resql = $this->db->query($query, $usesavepoint, $type, $result_mode);
376 $this->startTime = microtime(
true);
377 $this->startMemory = memory_get_usage(
true);
390 if (isset($_COOKIE[
'debugbar_full_tracing'])) {
391 return $_COOKIE[
'debugbar_full_tracing'] ===
'1';
405 $endTime = microtime(
true);
406 $duration = $endTime - $this->startTime;
407 $endMemory = memory_get_usage(
true);
408 $memoryDelta = $endMemory - $this->startMemory;
413 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
416 $this->queries[] = array(
418 'duration' => $duration,
419 'memory_usage' => $memoryDelta,
420 'is_success' => $resql ?
true :
false,
421 'error_code' => $resql ? null : $this->db->lasterrno(),
422 'error_message' => $resql ? null : $this->db->lasterror(),
423 'backtrace' => $backtrace
438 public function connect($host, $login, $passwd, $name, $port = 0)
440 return $this->db->connect($host, $login, $passwd, $name, $port);
450 public function plimit($limit = 0, $offset = 0)
452 return $this->db->plimit($limit, $offset);
463 return $this->db->getServerParametersValues($filter);
474 return $this->db->getServerStatusValues($filter);
484 return $this->db->getDefaultCollationDatabase();
498 return $this->db->num_rows($resultset);
508 return $this->db->getPathOfDump();
518 return $this->db->getDriverInfo();
528 return $this->db->errno();
543 public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys =
null, $fulltext_keys =
null, $keys =
null)
545 return $this->db->DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys, $fulltext_keys, $keys);
556 return $this->db->DDLDropTable($table);
566 return $this->db->getListOfCharacterSet();
578 public function DDLAddField($table, $field_name, $field_desc, $field_position =
"")
580 return $this->db->DDLAddField($table, $field_name, $field_desc, $field_position);
592 return $this->db->DDLDropField($table, $field_name);
605 return $this->db->DDLUpdateField($table, $field_name, $field_desc);
615 return $this->db->getListOfCollation();
627 return $this->db->DDLDescTable($table, $field);
637 return $this->db->getVersion();
647 return $this->db->getDefaultCharacterSetDatabase();
659 public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
661 return $this->db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
674 public function jdate($string, $gm =
false)
677 return $this->db->jdate($string, $gm);
688 public function encrypt($fieldorvalue, $withQuotes = 1)
690 return $this->db->encrypt($fieldorvalue, $withQuotes);
701 return $this->db->commit($log);
712 return $this->db->DDLInfoTable($table);
721 public function free($resultset =
null)
723 $this->db->free($resultset);
734 return $this->db->close();
744 return $this->db->lastqueryerror();
754 return $this->db->DDLGetConnectId();
767 return $this->db->fetch_object($resultset);
780 return $this->db->select_db($database);
Class to manage Dolibarr database access.
escape($stringtoencode)
Escape a string to insert data.
convertSQLFromMysql($line, $type='ddl')
Convert a SQL request in Mysql syntax to native syntax.
const VERSIONMIN
@const Version min database
jdate($string, $gm=false)
Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -...
begin($textinlog='')
Start transaction.
getDriverInfo()
Return version of database client driver.
free($resultset=null)
Free last resultset used.
getPathOfDump()
Return full path of dump program.
getPathOfRestore()
Return full path of restore program.
select_db($database)
Select a database.
isFullTracingEnabled()
Check if full query tracing is enabled.
rollback($log='')
Cancel a transaction and go back to initial data values.
encrypt($fieldorvalue, $withQuotes=1)
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple ...
order($sortfield=null, $sortorder=null)
Define sort criteria of request.
fetch_array($resultset)
Return datas as an array.
getVersionArray()
Return version of database server into an array.
num_rows($resultset)
Return number of lines for result of a SELECT.
escapeforlike($stringtoencode)
Escape a string to insert data into a like.
commit($log='')
Validate a database transaction.
fetch_row($resultset)
Return datas as an array.
DDLCreateDb($database, $charset='', $collation='', $owner='')
Create a new database Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated We fo...
DDLAddField($table, $field_name, $field_desc, $field_position="")
Create a new field into table.
affected_rows($resultset)
Return the number of lines into the result of a request INSERT, DELETE or UPDATE.
DDLListTablesFull($database, $table='')
List tables into a database with table info.
decrypt($value)
Decrypt sensitive data in database.
DDLInfoTable($table)
List information of columns into a table.
lasterror()
Return last error label.
__construct($db)
Constructor.
getDefaultCollationDatabase()
Return collation used in database.
last_insert_id($tab, $fieldid='rowid')
Get last ID after an insert INSERT.
ifsql($test, $resok, $resko)
Format a SQL IF.
getServerParametersValues($filter='')
Return value of server parameters.
DDLGetConnectId()
Return connection ID.
regexpsql($subject, $pattern, $sqlstring=0)
format a sql regexp
lastqueryerror()
Return last query in error.
getDefaultCharacterSetDatabase()
Return charset used to store data in database.
getListOfCharacterSet()
Return list of available charset that can be used to store data in database.
endTracing($sql, $resql)
End query tracing.
getListOfCollation()
Return list of available collation that can be used for database.
connect($host, $login, $passwd, $name, $port=0)
Connection to server.
fetch_object($resultset)
Returns the current line (as an object) for the resultset cursor.
DDLDropField($table, $field_name)
Drop a field from table.
lastquery()
Return last request executed with query()
errno()
Return generic error code of last operation.
DDLDescTable($table, $field="")
Return a pointer of line with description of a table or field.
lasterrno()
Return last error code.
DDLListTables($database, $table='')
List tables into a database.
plimit($limit=0, $offset=0)
Define limits and offset of request.
idate($param, $gm='tzserver')
Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date fiel...
DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys=null, $fulltext_keys=null, $keys=null)
Create a table into database.
getServerStatusValues($filter='')
Return value of server status.
startTracing()
Start query tracing.
DDLUpdateField($table, $field_name, $field_desc)
Update format of a field into a table.
close()
Close database connection.
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
getVersion()
Return version of database server.
error()
Return description of last error.
const LABEL
@const Database label
DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
Create a user and privileges to connect to database (even if database does not exists yet)
DDLDropTable($table)
Drop a table into database.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...