dolibarr 21.0.0-beta
|
Class to manage Dolibarr database access. More...
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. | |
stddevpop ($nameoffield) | |
Return SQL string to aggregate using the Standard Deviation of population. | |
hintindex ($nameofindex, $mode=1) | |
Return SQL string to force an index. | |
regexpsql ($subject, $pattern, $sqlstring=0) | |
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, $allowsspace=0, $allowschars=1) | |
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 whatever 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. | |
Public Member Functions inherited from Database | |
fetch_row ($resultset) | |
Return data as an array @TODO deprecate this. | |
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. | |
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. | |
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 data 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) | |
Connection 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) | |
DDLInfoTable ($table) | |
List information of columns into a table. | |
encrypt ($fieldorvalue, $withQuotes=1) | |
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings. | |
free ($resultset=null) | |
Free last resultset used. | |
close () | |
Close database connection. | |
DDLGetConnectId () | |
Return connection ID. | |
fetch_object ($resultset) | |
Returns the current line (as an object) for the resultset cursor. | |
select_db ($database) | |
Select a database. | |
Class to manage Dolibarr database access.
Definition at line 33 of file DoliDB.class.php.
DoliDB::begin | ( | $textinlog = '' | ) |
Start transaction.
string | $textinlog | Add a small text into log. '' by default. |
Implements Database.
Reimplemented in TraceableDB.
Definition at line 197 of file DoliDB.class.php.
References dol_syslog(), and Database\query().
DoliDB::commit | ( | $log = '' | ) |
Validate a database transaction.
string | $log | Add more log to default log line |
Implements Database.
Reimplemented in TraceableDB.
Definition at line 222 of file DoliDB.class.php.
References dol_syslog(), and Database\query().
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
string | $sql | The sql query string |
Definition at line 397 of file DoliDB.class.php.
References Database\fetch_object(), Database\free(), and Database\query().
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.
string | $sql | The sql query string. Must end with "... LIMIT x" |
Definition at line 423 of file DoliDB.class.php.
References Database\fetch_object(), Database\free(), Database\num_rows(), and Database\query().
DoliDB::getVersionArray | ( | ) |
Return version of database server into an array.
Implements Database.
Reimplemented in TraceableDB.
Definition at line 288 of file DoliDB.class.php.
References Database\getVersion().
DoliDB::hintindex | ( | $nameofindex, | |
$mode = 1 ) |
Return SQL string to force an index.
string | $nameofindex | Name of index |
int | $mode | 0=Use, 1=Force |
Reimplemented in DoliDBMysqli.
Definition at line 128 of file DoliDB.class.php.
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
int | $param | Date TMS to convert |
'gmt'|'tzserver' | $gm 'gmt'=Input information are GMT values, 'tzserver'=Local to server TZ |
Implements Database.
Reimplemented in TraceableDB.
Definition at line 160 of file DoliDB.class.php.
References dol_print_date().
DoliDB::ifsql | ( | $test, | |
$resok, | |||
$resko ) |
Format a SQL IF.
string | $test | Test string (example: 'cd.statut=0', 'field IS NULL') |
string | $resok | resultat si test equal |
string | $resko | resultat si test non equal |
Implements Database.
Reimplemented in DoliDBPgsql, and TraceableDB.
Definition at line 104 of file DoliDB.class.php.
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 whatever is server TZ if $gm='gmt'.
string | $string | Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) |
mixed | $gm | 'gmt'=Input information are GMT values, 'tzserver'=Local to server TZ |
Implements Database.
Reimplemented in TraceableDB.
Definition at line 367 of file DoliDB.class.php.
References dol_mktime().
DoliDB::lasterrno | ( | ) |
Return last error code.
Implements Database.
Reimplemented in TraceableDB.
Definition at line 171 of file DoliDB.class.php.
Referenced by DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().
DoliDB::lasterror | ( | ) |
Return last error label.
Implements Database.
Reimplemented in TraceableDB.
Definition at line 353 of file DoliDB.class.php.
Referenced by DoliDBPgsql\DDLDropField(), DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().
DoliDB::lastquery | ( | ) |
Return last request executed with query()
Implements Database.
Reimplemented in TraceableDB.
Definition at line 298 of file DoliDB.class.php.
Referenced by DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().
DoliDB::lastqueryerror | ( | ) |
Return last query in error.
Implements Database.
Reimplemented in TraceableDB.
Definition at line 384 of file DoliDB.class.php.
Referenced by DoliDBMysqli\query(), DoliDBPgsql\query(), and DoliDBSqlite3\query().
DoliDB::order | ( | $sortfield = '', | |
$sortorder = '' ) |
Define sort criteria of request.
string | $sortfield | List of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb' |
string | $sortorder | Sort 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. |
Implements Database.
Reimplemented in TraceableDB.
Definition at line 310 of file DoliDB.class.php.
DoliDB::plimit | ( | $limit = 0, | |
$offset = 0 ) |
Define limits and offset of request.
int | $limit | Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
int | $offset | Numero of line from where starting fetch |
Implements Database.
Reimplemented in DoliDBPgsql, and TraceableDB.
Definition at line 267 of file DoliDB.class.php.
References $conf.
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).
Definition at line 91 of file DoliDB.class.php.
DoliDB::regexpsql | ( | $subject, | |
$pattern, | |||
$sqlstring = 0 ) |
Format a SQL REGEXP.
string | $subject | Field name to test |
string | $pattern | SQL pattern to match |
int | $sqlstring | 0=the string being tested is a hard coded string, 1=the string is a field |
Reimplemented in DoliDBPgsql.
Definition at line 142 of file DoliDB.class.php.
References Database\escape().
DoliDB::rollback | ( | $log = '' | ) |
Cancel a transaction and go back to initial data values.
string | $log | Add more log to default log line |
Implements Database.
Reimplemented in TraceableDB.
Definition at line 246 of file DoliDB.class.php.
References dol_syslog(), and Database\query().
DoliDB::sanitize | ( | $stringtosanitize, | |
$allowsimplequote = 0, | |||
$allowsequals = 0, | |||
$allowsspace = 0, | |||
$allowschars = 1 ) |
Sanitize a string for SQL forging.
string | $stringtosanitize | String to escape |
int | $allowsimplequote | 1=Allow simple quotes in string. When string is used as a list of SQL string ('aa', 'bb', ...) |
int | $allowsequals | 1=Allow equals sign |
int | $allowsspace | 1=Allow space char |
int | $allowschars | 1=Allow a-z chars |
Definition at line 186 of file DoliDB.class.php.
Referenced by DoliDBPgsql\DDLAddField(), DoliDBPgsql\DDLCreateTable(), DoliDBPgsql\DDLDropField(), and DoliDBPgsql\DDLUpdateField().
DoliDB::stddevpop | ( | $nameoffield | ) |
Return SQL string to aggregate using the Standard Deviation of population.
string | $nameoffield | Name of field |
Implements Database.
Definition at line 116 of file DoliDB.class.php.