DoliDB
abstract class DoliDB implements Database (View source)
Class to manage Dolibarr database access
Constants
| VERSIONMIN |
Force subclass to implement VERSIONMIN - required DB version |
| LABEL |
Force subclass to implement LABEL - description of DB type |
Properties
| false|resource|mysqli|mysqliDoli|SQLite3|Connection|DoliDB | $db | ||
| string | $type | ||
| string | $forcecharset | ||
| string | $forcecollate | ||
| bool | $connected | ||
| bool | $database_selected | ||
| string | $database_name | ||
| string | $database_user | ||
| string | $database_host | ||
| int | $database_port | ||
| int | $transaction_opened | ||
| string | $lastquery | ||
| string | $lastqueryerror | ||
| string | $lasterror | ||
| string | $lasterrno | ||
| string | $prefix_db | ||
| bool | $ok | ||
| string | $error |
Methods
Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...).
Format a SQL IF
Return SQL string to aggregate using the Standard Deviation of population
Return SQL string to force an index
Format a SQL REGEXP
Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
Return last error code
Sanitize a string for SQL forging
Start transaction
Validate a database transaction
Cancel a transaction and go back to initial data values
Define limits and offset of request
Return version of database server into an array
Return last request executed with query()
Define sort criteria of request
Return last error label
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 whatever is server TZ if $gm='gmt'
Return last query in error
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
Return all results from query as an array of objects. Using this is a bad practice and is discouraged.
Get the last ID of an auto-increment field of a table
Prepare a SQL statement for execution
Details
string
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).
string
ifsql(string $test, string $resok, string $resko)
Format a SQL IF
string
stddevpop(string $nameoffield)
Return SQL string to aggregate using the Standard Deviation of population
string
hintindex(string $nameofindex, int $mode = 1)
Return SQL string to force an index
string
regexpsql(string $subject, string $pattern, int $sqlstring = 0)
Format a SQL REGEXP
string
idate(int $param, "gmt"|"tzserver" $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
string
lasterrno()
Return last error code
string
sanitize(string $stringtosanitize, int $allowsimplequote = 0, int $allowsequals = 0, int $allowsspace = 0, int $allowschars = 1)
Sanitize a string for SQL forging
int
begin(string $textinlog = '')
Start transaction
int
commit(string $log = '')
Validate a database transaction
int
rollback(string $log = '')
Cancel a transaction and go back to initial data values
@param string $log Add more log to default log line
string
plimit(int $limit = 0, int $offset = 0)
Define limits and offset of request
string[]
getVersionArray()
Return version of database server into an array
string
lastquery()
Return last request executed with query()
string
order(string $sortfield = '', string $sortorder = '')
Define sort criteria of request
string
lasterror()
Return last error label
int|""
jdate(string $string, bool $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 whatever is server TZ if $gm='gmt'
@param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
string
lastqueryerror()
Return last query in error
bool|int|object
getRow(string $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
false|object[]
getRows(string $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.
int
getNextAutoIncrementId(string $table)
Get the last ID of an auto-increment field of a table
mixed
prepare(string $sql)
Prepare a SQL statement for execution
This method must be implemented by subclasses.