dolibarr 18.0.6
DoliDB Class Reference

Class to manage Dolibarr database access. More...

Inheritance diagram for DoliDB:
Collaboration diagram for DoliDB:

Public Member Functions

 prefix ()
 Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...).
 
 ifsql ($test, $resok, $resko)
 Format a SQL IF.
 
 hintindex ($nameofindex)
 Return SQL string to force an index.
 
 regexpsql ($subject, $pattern, $sqlstring=false)
 Format a SQL REGEXP.
 
 idate ($param, $gm='tzserver')
 Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
 
 lasterrno ()
 Return last error code.
 
 sanitize ($stringtosanitize, $allowsimplequote=0, $allowsequals=0)
 Sanitize a string for SQL forging.
 
 begin ($textinlog='')
 Start transaction.
 
 commit ($log='')
 Validate a database transaction.
 
 rollback ($log='')
 Cancel a transaction and go back to initial data values.
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request.
 
 getVersionArray ()
 Return version of database server into an array.
 
 lastquery ()
 Return last request executed with query()
 
 order ($sortfield='', $sortorder='')
 Define sort criteria of request.
 
 lasterror ()
 Return last error label.
 
 jdate ($string, $gm='tzserver')
 Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -> 3600 with server TZ = +1 and $gm='tzserver' 19700101020000 -> 7200 whaterver is server TZ if $gm='gmt'.
 
 lastqueryerror ()
 Return last query in error.
 
 getRow ($sql)
 Return first result from query as object Note : This method executes a given SQL query and retrieves the first row of results as an object.
 
 getRows ($sql)
 Return all results from query as an array of objects Note : This method executes a given SQL query and retrieves all row of results as an array of objects.
 
- Public Member Functions inherited from Database
 fetch_row ($resultset)
 Return datas as an array.
 
 idate ($param)
 Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
 
 DDLCreateDb ($database, $charset='', $collation='', $owner='')
 Create a new database Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated We force to create database with charset this->forcecharset and collate this->forcecollate.
 
 affected_rows ($resultset)
 Return the number of lines in the result of a request INSERT, DELETE or UPDATE.
 
 error ()
 Return description of last error.
 
 DDLListTables ($database, $table='')
 List tables into a database.
 
 DDLListTablesFull ($database, $table='')
 List tables into a database with table type.
 
 decrypt ($value)
 Decrypt sensitive data in database.
 
 fetch_array ($resultset)
 Return datas as an array.
 
 escape ($stringtoencode)
 Escape a string to insert data.
 
 escapeforlike ($stringtoencode)
 Escape a string to insert data into a like.
 
 sanitize ($stringtosanitize)
 Sanitize a string for SQL forging.
 
 last_insert_id ($tab, $fieldid='rowid')
 Get last ID after an insert INSERT.
 
 getPathOfRestore ()
 Return full path of restore program.
 
 query ($query, $usesavepoint=0, $type='auto', $result_mode=0)
 Execute a SQL request and return the resultset.
 
 connect ($host, $login, $passwd, $name, $port=0)
 Connexion to server.
 
 getServerParametersValues ($filter='')
 Return value of server parameters.
 
 getServerStatusValues ($filter='')
 Return value of server status.
 
 getDefaultCollationDatabase ()
 Return collation used in database.
 
 num_rows ($resultset)
 Return number of lines for result of a SELECT.
 
 getPathOfDump ()
 Return full path of dump program.
 
 getDriverInfo ()
 Return version of database client driver.
 
 errno ()
 Return generic error code of last operation.
 
 DDLCreateTable ($table, $fields, $primary_key, $type, $unique_keys=null, $fulltext_keys=null, $keys=null)
 Create a table into database.
 
 DDLDropTable ($table)
 Drop a table into database.
 
 getListOfCharacterSet ()
 Return list of available charset that can be used to store data in database.
 
 DDLAddField ($table, $field_name, $field_desc, $field_position="")
 Create a new field into table.
 
 DDLDropField ($table, $field_name)
 Drop a field from table.
 
 DDLUpdateField ($table, $field_name, $field_desc)
 Update format of a field into a table.
 
 getListOfCollation ()
 Return list of available collation that can be used for database.
 
 DDLDescTable ($table, $field="")
 Return a pointer of line with description of a table or field.
 
 getVersion ()
 Return version of database server.
 
 getDefaultCharacterSetDatabase ()
 Return charset used to store data in database.
 
 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)
 
 encrypt ($fieldorvalue, $withQuotes=1)
 Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
 
 DDLInfoTable ($table)
 List information of columns into a table.
 
 free ($resultset=null)
 Free last resultset used.
 
 close ()
 Close database connexion.
 
 DDLGetConnectId ()
 Return connexion ID.
 
 fetch_object ($resultset)
 Returns the current line (as an object) for the resultset cursor.
 
 select_db ($database)
 Select a database.
 

Additional Inherited Members

- Static Public Member Functions inherited from Database
static convertSQLFromMysql ($line, $type='ddl')
 Convert a SQL request in Mysql syntax to native syntax.
 

Detailed Description

Class to manage Dolibarr database access.

Definition at line 30 of file DoliDB.class.php.

Member Function Documentation

◆ begin()

DoliDB::begin ( $textinlog = '')

Start transaction.

Parameters
string$textinlogAdd a small text into log. '' by default.
Returns
int 1 if transaction successfuly opened or already opened, 0 if error

Implements Database.

Reimplemented in TraceableDB.

Definition at line 175 of file DoliDB.class.php.

References dol_syslog(), and Database\query().

◆ commit()

DoliDB::commit ( $log = '')

Validate a database transaction.

Parameters
string$logAdd more log to default log line
Returns
int 1 if validation is OK or transaction level no started, 0 if ERROR

Implements Database.

Reimplemented in TraceableDB.

Definition at line 198 of file DoliDB.class.php.

References dol_syslog(), and Database\query().

◆ getRow()

DoliDB::getRow ( $sql)

Return first result from query as object Note : This method executes a given SQL query and retrieves the first row of results as an object.

It should only be used with SELECT queries Dont add LIMIT to your query, it will be added by this method

Parameters
string$sqlThe sql query string
Returns
bool|int|object False on failure, 0 on empty, object on success

Definition at line 373 of file DoliDB.class.php.

References Database\fetch_object(), and Database\query().

◆ getRows()

DoliDB::getRows ( $sql)

Return all results from query as an array of objects Note : This method executes a given SQL query and retrieves all row of results as an array of objects.

It should only be used with SELECT queries be carefull with this method use it only with some limit of results to avoid performences loss.

Parameters
string$sqlThe sql query string
Returns
bool|array Result
Deprecated

Definition at line 399 of file DoliDB.class.php.

References Database\fetch_object(), Database\num_rows(), and Database\query().

◆ getVersionArray()

DoliDB::getVersionArray ( )

Return version of database server into an array.

Returns
array Version array

Implements Database.

Reimplemented in TraceableDB.

Definition at line 264 of file DoliDB.class.php.

References Database\getVersion().

◆ hintindex()

DoliDB::hintindex ( $nameofindex)

Return SQL string to force an index.

Parameters
string$nameofindexName of index
Returns
string SQL string

Reimplemented in DoliDBMysqli.

Definition at line 108 of file DoliDB.class.php.

◆ idate()

DoliDB::idate ( $param,
$gm = 'tzserver' )

Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.

Function to use to build INSERT, UPDATE or WHERE predica

Parameters
int$paramDate TMS to convert
mixed$gm'gmt'=Input informations are GMT values, 'tzserver'=Local to server TZ
Returns
string Date in a string YYYY-MM-DD HH:MM:SS

Reimplemented in TraceableDB.

Definition at line 140 of file DoliDB.class.php.

References dol_print_date().

◆ ifsql()

DoliDB::ifsql ( $test,
$resok,
$resko )

Format a SQL IF.

Parameters
string$testTest string (example: 'cd.statut=0', 'field IS NULL')
string$resokresultat si test egal
string$reskoresultat si test non egal
Returns
string SQL string

Implements Database.

Reimplemented in DoliDBPgsql, and TraceableDB.

Definition at line 96 of file DoliDB.class.php.

◆ jdate()

DoliDB::jdate ( $string,
$gm = 'tzserver' )

Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -> 3600 with server TZ = +1 and $gm='tzserver' 19700101020000 -> 7200 whaterver is server TZ if $gm='gmt'.

Parameters
string$stringDate in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
mixed$gm'gmt'=Input informations are GMT values, 'tzserver'=Local to server TZ
Returns
int|string Date TMS or ''

Implements Database.

Reimplemented in TraceableDB.

Definition at line 343 of file DoliDB.class.php.

References dol_mktime().

◆ lasterrno()

DoliDB::lasterrno ( )

Return last error code.

Returns
string lasterrno

Implements Database.

Reimplemented in TraceableDB.

Definition at line 151 of file DoliDB.class.php.

Referenced by DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().

◆ lasterror()

DoliDB::lasterror ( )

Return last error label.

Returns
string Last error

Implements Database.

Reimplemented in TraceableDB.

Definition at line 329 of file DoliDB.class.php.

Referenced by DoliDBPgsql\DDLDropField(), DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().

◆ lastquery()

DoliDB::lastquery ( )

Return last request executed with query()

Returns
string Last query

Implements Database.

Reimplemented in TraceableDB.

Definition at line 274 of file DoliDB.class.php.

Referenced by DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().

◆ lastqueryerror()

DoliDB::lastqueryerror ( )

Return last query in error.

Returns
string lastqueryerror

Implements Database.

Reimplemented in TraceableDB.

Definition at line 360 of file DoliDB.class.php.

Referenced by DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().

◆ order()

DoliDB::order ( $sortfield = '',
$sortorder = '' )

Define sort criteria of request.

Parameters
string$sortfieldList of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb'
string$sortorderSort order, separated by comma. Example: 'ASC,DESC'. Note: If the quantity fo sortorder values is lower than sortfield, we used the last value for missing values.
Returns
string String to provide syntax of a sort sql string

Implements Database.

Reimplemented in TraceableDB.

Definition at line 286 of file DoliDB.class.php.

◆ plimit()

DoliDB::plimit ( $limit = 0,
$offset = 0 )

Define limits and offset of request.

Parameters
int$limitMaximum number of lines returned (-1=conf->liste_limit, 0=no limit)
int$offsetNumero of line from where starting fetch
Returns
string String with SQL syntax to add a limit and offset

Implements Database.

Reimplemented in DoliDBPgsql, and TraceableDB.

Definition at line 243 of file DoliDB.class.php.

◆ prefix()

DoliDB::prefix ( )

Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...).

Otherwise return MAIN_DB_PREFIX (common use).

Returns
string The DB prefix

Definition at line 83 of file DoliDB.class.php.

◆ regexpsql()

DoliDB::regexpsql ( $subject,
$pattern,
$sqlstring = false )

Format a SQL REGEXP.

Parameters
string$subjectstring tested
string$patternSQL pattern to match
string$sqlstringwhether or not the string being tested is an SQL expression
Returns
string SQL string

Reimplemented in DoliDBPgsql.

Definition at line 122 of file DoliDB.class.php.

◆ rollback()

DoliDB::rollback ( $log = '')

Cancel a transaction and go back to initial data values.

Parameters
string$logAdd more log to default log line
Returns
resource|int 1 if cancelation is ok or transaction not open, 0 if error

Implements Database.

Reimplemented in TraceableDB.

Definition at line 222 of file DoliDB.class.php.

References dol_syslog(), and Database\query().

◆ sanitize()

DoliDB::sanitize ( $stringtosanitize,
$allowsimplequote = 0,
$allowsequals = 0 )

Sanitize a string for SQL forging.

Parameters
string$stringtosanitizeString to escape
int$allowsimplequote1=Allow simple quotes in string. When string is used as a list of SQL string ('aa', 'bb', ...)
string$allowsequals1=Allow equals sign
Returns
string String escaped

Definition at line 164 of file DoliDB.class.php.


The documentation for this class was generated from the following file: