|
dolibarr 20.0.5
|
Class to manage Dolibarr database access for an SQL database. More...

Public Member Functions | |
| ifsql ($test, $resok, $resko) | |
| Format a SQL IF. | |
| stddevpop ($nameoffield) | |
| Return SQL string to aggregate using the Standard Deviation of population. | |
| fetch_row ($resultset) | |
| Return datas as an array @TODO deprecate this. | |
| idate ($param) | |
| 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. | |
| begin ($textinlog='') | |
| Start transaction. | |
| 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. | |
| getVersionArray () | |
| Return version of database server into an array. | |
| 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. | |
| lastquery () | |
| Return last request executed with query() | |
| order ($sortfield='', $sortorder='') | |
| Define sort criteria of request. | |
| decrypt ($value) | |
| Decrypt sensitive data in database. | |
| fetch_array ($resultset) | |
| Return datas as an array. | |
| lasterror () | |
| Return last error label. | |
| 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. | |
| rollback ($log='') | |
| Canceling a transaction and returning to old values. | |
| 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. | |
| plimit ($limit=0, $offset=0) | |
| Define limits and offset of request. | |
| 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. | |
| jdate ($string, $gm=false) | |
| Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -> 3600 with TZ+1 and gmt=0 19700101020000 -> 7200 whaterver is TZ if gmt=1. | |
| encrypt ($fieldorvalue, $withQuotes=1) | |
| Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings. | |
| commit ($log='') | |
| Validate a database transaction. | |
| free ($resultset=null) | |
| Free last resultset used. | |
| close () | |
| Close database connection. | |
| lastqueryerror () | |
| Return last query in error. | |
| 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 for an SQL database.
Definition at line 28 of file Database.interface.php.
| Database::affected_rows | ( | $resultset | ) |
Return the number of lines in the result of a request INSERT, DELETE or UPDATE.
| mysqli_result | resource | SQLite3Result | $resultset | Cursor of the desired request |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::begin | ( | $textinlog = '' | ) |
Start transaction.
| string | $textinlog | Add a small text into log. '' by default. |
Implemented in DoliDB, and TraceableDB.
| Database::close | ( | ) |
Close database connection.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::commit | ( | $log = '' | ) |
Validate a database transaction.
| string | $log | Add more log to default log line |
Implemented in DoliDB, and TraceableDB.
| Database::connect | ( | $host, | |
| $login, | |||
| $passwd, | |||
| $name, | |||
| $port = 0 ) |
Connection to server.
| string | $host | Database server host |
| string | $login | Login |
| string | $passwd | Password |
| string | $name | Name of database (not used for mysql, used for pgsql) |
| int | $port | Port of database server |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::convertSQLFromMysql | ( | $line, | |
| $type = 'ddl' ) |
Convert a SQL request in Mysql syntax to native syntax.
| string | $line | SQL request line to convert |
| string | $type | Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
Implemented in DoliDBMysqli, DoliDBSqlite3, and TraceableDB.
| Database::DDLAddField | ( | $table, | |
| $field_name, | |||
| $field_desc, | |||
| $field_position = "" ) |
Create a new field into table.
| string | $table | Name of table |
| string | $field_name | Name of field to add |
| array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string} | $field_desc Associative array of description of the field to insert [parameter name][parameter value] | |
| string | $field_position | Optional ex .: "after field stuff" |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::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.
| string | $database | Database name to create |
| string | $charset | Charset used to store data |
| string | $collation | Charset used to sort data |
| string | $owner | Username of database owner |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLCreateTable | ( | $table, | |
| $fields, | |||
| $primary_key, | |||
| $type, | |||
| $unique_keys = null, | |||
| $fulltext_keys = null, | |||
| $keys = null ) |
Create a table into database.
| string | $table | Name of table |
| array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}> | $fields Associative table [field name][table of descriptions] | |
| string | $primary_key | Name of the field that will be the primary key |
| string | $type | Type of the table |
| array | $unique_keys | Associative array Name of fields that will be unique key => value |
| array | $fulltext_keys | Field name table that will be indexed in fulltext |
| array | $keys | Table of key fields names => value |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| 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)
| string | $dolibarr_main_db_host | Server IP |
| string | $dolibarr_main_db_user | Username to create |
| string | $dolibarr_main_db_pass | User password to create |
| string | $dolibarr_main_db_name | Database name where user must be granted |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLDescTable | ( | $table, | |
| $field = "" ) |
Return a pointer of line with description of a table or field.
| string | $table | Name of table |
| string | $field | Optional : Name of field if we want description of field |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLDropField | ( | $table, | |
| $field_name ) |
Drop a field from table.
| string | $table | Name of table |
| string | $field_name | Name of field to drop |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLDropTable | ( | $table | ) |
Drop a table into database.
| string | $table | Name of table |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLGetConnectId | ( | ) |
Return connection ID.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLInfoTable | ( | $table | ) |
List information of columns into a table.
| string | $table | Name of table |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLListTables | ( | $database, | |
| $table = '' ) |
List tables into a database.
| string | $database | Name of database |
| string | $table | Name of table filter ('xxx') |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLListTablesFull | ( | $database, | |
| $table = '' ) |
List tables into a database with table type.
| string | $database | Name of database |
| string | $table | Name of table filter ('xxx') |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::DDLUpdateField | ( | $table, | |
| $field_name, | |||
| $field_desc ) |
Update format of a field into a table.
| string | $table | Name of table |
| string | $field_name | Name of field to modify |
| array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string} | $field_desc Array with description of field format |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::decrypt | ( | $value | ) |
Decrypt sensitive data in database.
| string | $value | Value to decrypt |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::encrypt | ( | $fieldorvalue, | |
| $withQuotes = 1 ) |
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
| string | $fieldorvalue | Field name or value to encrypt |
| int | $withQuotes | Return string including the SQL simple quotes. This param must always be 1 (Value 0 is bugged and deprecated). |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::errno | ( | ) |
Return generic error code of last operation.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::error | ( | ) |
Return description of last error.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::escape | ( | $stringtoencode | ) |
Escape a string to insert data.
| string | $stringtoencode | String to escape |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
Referenced by DoliDB\regexpsql().
| Database::escapeforlike | ( | $stringtoencode | ) |
Escape a string to insert data into a like.
Can be used this way: LIKE '%".dbhandler->escape(dbhandler->escapeforlike(...))."'
| string | $stringtoencode | String to escape |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::fetch_array | ( | $resultset | ) |
Return datas as an array.
| mysqli_result | resource | SQLite3Result | $resultset | Resultset of request |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::fetch_object | ( | $resultset | ) |
Returns the current line (as an object) for the resultset cursor.
| mysqli_result | resource | PgSql\Connection | SQLite3Result | $resultset | Handler of the desired request |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
Referenced by DoliDB\getRow(), DoliDB\getRows(), and Societe\replaceThirdparty().
| Database::fetch_row | ( | $resultset | ) |
Return datas as an array @TODO deprecate this.
Use fetch_object() so you can access a field with its name instead of using an index of position of field.
| mysqli_result | resource | SQLite3Result | $resultset | Resultset of request |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::free | ( | $resultset = null | ) |
Free last resultset used.
| resource | mysqli_result | SQLite3Result | $resultset | Free cursor |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
Referenced by DoliDB\getRow(), and DoliDB\getRows().
| Database::getDefaultCharacterSetDatabase | ( | ) |
Return charset used to store data in database.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getDefaultCollationDatabase | ( | ) |
Return collation used in database.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getDriverInfo | ( | ) |
Return version of database client driver.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getListOfCharacterSet | ( | ) |
Return list of available charset that can be used to store data in database.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getListOfCollation | ( | ) |
Return list of available collation that can be used for database.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getPathOfDump | ( | ) |
Return full path of dump program.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getPathOfRestore | ( | ) |
Return full path of restore program.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getServerParametersValues | ( | $filter = '' | ) |
Return value of server parameters.
| string | $filter | Filter list on a particular value |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getServerStatusValues | ( | $filter = '' | ) |
Return value of server status.
| string | $filter | Filter list on a particular value |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::getVersion | ( | ) |
Return version of database server.
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
Referenced by DoliDB\getVersionArray().
| Database::getVersionArray | ( | ) |
Return version of database server into an array.
Implemented in DoliDB, and TraceableDB.
| Database::idate | ( | $param | ) |
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 |
| Database::ifsql | ( | $test, | |
| $resok, | |||
| $resko ) |
Format a SQL IF.
| string | $test | Test string (example: 'cd.statut=0', 'field IS NULL') |
| string | $resok | result if test is equal |
| string | $resko | result if test is not equal |
Implemented in DoliDB, DoliDBPgsql, and TraceableDB.
| Database::jdate | ( | $string, | |
| $gm = false ) |
Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -> 3600 with TZ+1 and gmt=0 19700101020000 -> 7200 whaterver is TZ if gmt=1.
| string | $string | Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) |
| bool | $gm | 1=Input information are GMT values, otherwise local to server TZ |
Implemented in DoliDB, and TraceableDB.
| Database::last_insert_id | ( | $tab, | |
| $fieldid = 'rowid' ) |
Get last ID after an insert INSERT.
| string | $tab | Table name concerned by insert. Not used under MySql but required for compatibility with Postgresql |
| string | $fieldid | Field name |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::lasterrno | ( | ) |
| Database::lasterror | ( | ) |
| Database::lastquery | ( | ) |
Return last request executed with query()
Implemented in DoliDB, and TraceableDB.
| Database::lastqueryerror | ( | ) |
| Database::num_rows | ( | $resultset | ) |
Return number of lines for result of a SELECT.
| mysqli_result | resource | SQLite3Result | $resultset | Resulset of requests |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
Referenced by DoliDB\getRows().
| Database::order | ( | $sortfield = '', | |
| $sortorder = '' ) |
Define sort criteria of request.
| string | $sortfield | List of sort fields |
| string | $sortorder | Sort order |
Implemented in DoliDB, and TraceableDB.
| Database::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 |
Implemented in DoliDB, DoliDBPgsql, and TraceableDB.
| Database::query | ( | $query, | |
| $usesavepoint = 0, | |||
| $type = 'auto', | |||
| $result_mode = 0 ) |
Execute a SQL request and return the resultset.
| string | $query | SQL query string |
| int | $usesavepoint | 0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions). Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
| string | $type | Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
| int | $result_mode | Result mode |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
Referenced by DoliDB\begin(), DoliDB\commit(), CommonObject\commonReplaceProduct(), CommonObject\commonReplaceThirdparty(), DoliDB\getRow(), DoliDB\getRows(), ActionComm\replaceProduct(), Societe\replaceThirdparty(), and DoliDB\rollback().
| Database::rollback | ( | $log = '' | ) |
Canceling a transaction and returning to old values.
| string | $log | Add more log to default log line |
Implemented in DoliDB, and TraceableDB.
| Database::sanitize | ( | $stringtosanitize | ) |
Sanitize a string for SQL forging.
| string | $stringtosanitize | String to escape |
| Database::select_db | ( | $database | ) |
Select a database.
| string | $database | Name of database |
Implemented in DoliDBMysqli, DoliDBPgsql, DoliDBSqlite3, and TraceableDB.
| Database::stddevpop | ( | $nameoffield | ) |
Return SQL string to aggregate using the Standard Deviation of population.
| string | $nameoffield | Name of field |
Implemented in DoliDB.