dolibarr
x.y.z
|
Class to manage Dolibarr database access for an SQL database. More...
Public Member Functions | |
ifsql ($test, $resok, $resko) | |
Format a SQL IF. More... | |
fetch_row ($resultset) | |
Return datas as an array. 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... | |
lasterrno () | |
Return last error code. More... | |
begin ($textinlog='') | |
Start transaction. 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... | |
getVersionArray () | |
Return version of database server into an array. 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... | |
lastquery () | |
Return last request executed with query() More... | |
order ($sortfield=null, $sortorder=null) | |
Define sort criteria of request. More... | |
decrypt ($value) | |
Decrypt sensitive data in database. More... | |
fetch_array ($resultset) | |
Return datas as an array. More... | |
lasterror () | |
Return last error label. 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... | |
rollback ($log='') | |
Canceling a transaction and returning to old values. 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) | |
Connexion to server. More... | |
plimit ($limit=0, $offset=0) | |
Define limits and offset of request. 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... | |
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. 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... | |
commit ($log='') | |
Validate a database transaction. More... | |
DDLInfoTable ($table) | |
List information of columns into a table. More... | |
free ($resultset=null) | |
Free last resultset used. More... | |
close () | |
Close database connexion. More... | |
lastqueryerror () | |
Return last query in error. More... | |
DDLGetConnectId () | |
Return connexion ID. More... | |
fetch_object ($resultset) | |
Returns the current line (as an object) for the resultset cursor. More... | |
select_db ($database) | |
Select a database. More... | |
Static Public Member Functions | |
static | convertSQLFromMysql ($line, $type='ddl') |
Convert a SQL request in Mysql syntax to native syntax. More... | |
Class to manage Dolibarr database access for an SQL database.
Definition at line 26 of file Database.interface.php.
Database::affected_rows | ( | $resultset | ) |
Return the number of lines in the result of a request INSERT, DELETE or UPDATE.
resource | $resultset | Cursor of the desired request |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::begin | ( | $textinlog = '' | ) |
Start transaction.
string | $textinlog | Add a small text into log. '' by default. |
Implemented in TraceableDB, and DoliDB.
Database::close | ( | ) |
Close database connexion.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::commit | ( | $log = '' | ) |
Validate a database transaction.
string | $log | Add more log to default log line |
Implemented in TraceableDB, and DoliDB.
Database::connect | ( | $host, | |
$login, | |||
$passwd, | |||
$name, | |||
$port = 0 |
|||
) |
Connexion 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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
|
static |
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 TraceableDB, DoliDBSqlite3, and DoliDBMysqli.
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 |
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
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 | $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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::DDLDropTable | ( | $table | ) |
Drop a table into database.
string | $table | Name of table |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::DDLGetConnectId | ( | ) |
Return connexion ID.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::DDLInfoTable | ( | $table | ) |
List information of columns into a table.
string | $table | Name of table |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::DDLListTables | ( | $database, | |
$table = '' |
|||
) |
List tables into a database.
string | $database | Name of database |
string | $table | Name of table filter ('xxx') |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
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 |
string | $field_desc | Array with description of field format |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::decrypt | ( | $value | ) |
Decrypt sensitive data in database.
string | $value | Value to decrypt |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::errno | ( | ) |
Return generic error code of last operation.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::error | ( | ) |
Return description of last error.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::escape | ( | $stringtoencode | ) |
Escape a string to insert data.
string | $stringtoencode | String to escape |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::escapeforlike | ( | $stringtoencode | ) |
Escape a string to insert data into a like.
string | $stringtoencode | String to escape |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::fetch_array | ( | $resultset | ) |
Return datas as an array.
resource | $resultset | Resultset of request |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::fetch_object | ( | $resultset | ) |
Returns the current line (as an object) for the resultset cursor.
resource | Connection | $resultset | Handler of the desired request |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::fetch_row | ( | $resultset | ) |
Return datas as an array.
resource | $resultset | Resultset of request |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::free | ( | $resultset = null | ) |
Free last resultset used.
resource | $resultset | Free cursor |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getDefaultCharacterSetDatabase | ( | ) |
Return charset used to store data in database.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getDefaultCollationDatabase | ( | ) |
Return collation used in database.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getDriverInfo | ( | ) |
Return version of database client driver.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getListOfCharacterSet | ( | ) |
Return list of available charset that can be used to store data in database.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getListOfCollation | ( | ) |
Return list of available collation that can be used for database.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getPathOfDump | ( | ) |
Return full path of dump program.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getPathOfRestore | ( | ) |
Return full path of restore program.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getServerParametersValues | ( | $filter = '' | ) |
Return value of server parameters.
string | $filter | Filter list on a particular value |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getServerStatusValues | ( | $filter = '' | ) |
Return value of server status.
string | $filter | Filter list on a particular value |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::getVersion | ( | ) |
Return version of database server.
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Referenced by DoliDB\getVersionArray().
Database::getVersionArray | ( | ) |
Return version of database server into an array.
Implemented in TraceableDB, and DoliDB.
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 TraceableDB, DoliDBPgsql, and DoliDB.
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 informations are GMT values, otherwise local to server TZ |
Implemented in TraceableDB, and DoliDB.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::lasterrno | ( | ) |
Database::lasterror | ( | ) |
Database::lastquery | ( | ) |
Return last request executed with query()
Implemented in TraceableDB, and DoliDB.
Database::lastqueryerror | ( | ) |
Database::num_rows | ( | $resultset | ) |
Return number of lines for result of a SELECT.
resource | $resultset | Resulset of requests |
Implemented in TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::order | ( | $sortfield = null , |
|
$sortorder = null |
|||
) |
Define sort criteria of request.
string | $sortfield | List of sort fields |
string | $sortorder | Sort order |
Implemented in TraceableDB, and DoliDB.
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 TraceableDB, DoliDBPgsql, and DoliDB.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.
Database::rollback | ( | $log = '' | ) |
Canceling a transaction and returning to old values.
string | $log | Add more log to default log line |
Implemented in TraceableDB, and DoliDB.
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 TraceableDB, DoliDBSqlite3, DoliDBPgsql, and DoliDBMysqli.