dolibarr  20.0.0-beta
Public Member Functions | Public Attributes | List of all members
DoliDB Class Reference

Class to manage Dolibarr database access. More...

Inheritance diagram for DoliDB:
Inheritance graph
[legend]
Collaboration diagram for DoliDB:
Collaboration graph
[legend]

Public Member Functions

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

Public Attributes

const VERSIONMIN = self::VERSIONMIN
 Force subclass to implement VERSIONMIN - required DB version.
 
const LABEL = self::LABEL
 Force subclass to implement LABEL - description of DB type.
 

Detailed Description

Class to manage Dolibarr database access.

Definition at line 33 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 successfully opened or already opened, 0 if error

Implements Database.

Reimplemented in TraceableDB.

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

◆ 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 219 of file DoliDB.class.php.

◆ 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 Don't 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 394 of file DoliDB.class.php.

References $sql.

◆ getRows()

DoliDB::getRows (   $sql)

Return all results from query as an array of objects.

Using this is a bad practice and is discouraged. Note : It should only be used with SELECT queries and with a limit. If you are not able to defined/know what can be the limit, it just means this function is not what you need. Do not use it.

Parameters
string$sqlThe sql query string. Must end with "... LIMIT x"
Returns
bool|array Result

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

References $sql.

◆ getVersionArray()

DoliDB::getVersionArray ( )

Return version of database server into an array.

Returns
string[] Version array

Implements Database.

Reimplemented in TraceableDB.

Definition at line 285 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 127 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 information 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 159 of file DoliDB.class.php.

◆ 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 equal
string$reskoresultat si test non equal
Returns
string SQL string

Implements Database.

Reimplemented in TraceableDB, and DoliDBPgsql.

Definition at line 104 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 information are GMT values, 'tzserver'=Local to server TZ
Returns
int|'' Date TMS or ''

Implements Database.

Reimplemented in TraceableDB.

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

◆ lasterrno()

DoliDB::lasterrno ( )

Return last error code.

Returns
string lasterrno

Implements Database.

Reimplemented in TraceableDB.

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

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

◆ lasterror()

DoliDB::lasterror ( )

Return last error label.

Returns
string Last error

Implements Database.

Reimplemented in TraceableDB.

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

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

◆ lastquery()

DoliDB::lastquery ( )

Return last request executed with query()

Returns
string Last query

Implements Database.

Reimplemented in TraceableDB.

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

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

◆ lastqueryerror()

DoliDB::lastqueryerror ( )

Return last query in error.

Returns
string lastqueryerror

Implements Database.

Reimplemented in TraceableDB.

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

◆ 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 for 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 307 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 TraceableDB, and DoliDBPgsql.

Definition at line 264 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 91 of file DoliDB.class.php.

◆ regexpsql()

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

Format a SQL REGEXP.

Parameters
string$subjectField name to test
string$patternSQL pattern to match
int$sqlstring0=the string being tested is a hard coded string, 1=the string is a field
Returns
string SQL string

Reimplemented in DoliDBPgsql.

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

References Database\escape().

◆ 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 cancellation is ok or transaction not open, 0 if error

Implements Database.

Reimplemented in TraceableDB.

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

◆ sanitize()

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

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', ...)
int$allowsequals1=Allow equals sign
int$allowsspace1=Allow space char
int$allowschars1=Allow a-z chars
Returns
string String escaped

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

◆ stddevpop()

DoliDB::stddevpop (   $nameoffield)

Return SQL string to aggregate using the Standard Deviation of population.

Parameters
string$nameoffieldName of field
Returns
string SQL string

Implements Database.

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


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