|
dolibarr 24.0.0-beta
|
Class to manage Dolibarr database access for a MySQL database using the MySQLi extension. More...


Public Member Functions | |
| __construct ($type, $host, $user, $pass, $name='', $port=0) | |
| Constructor. | |
| hintindex ($nameofindex, $mode=1) | |
| Return SQL string to force an index. | |
| convertSQLFromMysql ($line, $type='ddl') | |
| Convert a SQL request in Mysql syntax to native syntax. | |
| select_db ($database) | |
| Select a database. | |
| connect ($host, $login, $passwd, $name, $port=0) | |
| Connect to server. | |
| getVersion () | |
| Return version of database server. | |
| getDriverInfo () | |
| Return version of database client driver. | |
| close () | |
| Close database connection. | |
| query ($query, $usesavepoint=0, $type='auto', $result_mode=0) | |
| Execute a SQL request and return the resultset. | |
| fetch_object ($resultset) | |
| Returns the current line (as an object) for the resultset cursor. | |
| fetch_array ($resultset) | |
| Return data as an array. | |
| fetch_row ($resultset) | |
| Return data as an array. | |
| num_rows ($resultset) | |
| Return number of lines for result of a SELECT. | |
| affected_rows ($resultset) | |
| Return the number of lines in the result of a request INSERT, DELETE or UPDATE. | |
| free ($resultset=null) | |
| Free the last pointer resultset used by this connection. | |
| escape ($stringtoencode) | |
| Escape a string to insert data. | |
| escapeforlike ($stringtoencode) | |
| Escape a string to insert data into a like. | |
| errno () | |
| Return generic error code of last operation. | |
| error () | |
| Return description of last error. | |
| last_insert_id ($tab, $fieldid='rowid') | |
| Get last ID after an insert INSERT. | |
| encrypt ($fieldorvalue, $withQuotes=1) | |
| Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings. | |
| decrypt ($value) | |
| Decrypt sensitive data in database. | |
| DDLGetConnectId () | |
| Return connection ID. | |
| 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. | |
| DDLListTables ($database, $table='') | |
| List tables into a database. | |
| DDLListTablesFull ($database, $table='') | |
| List tables into a database. | |
| DDLInfoTable ($table) | |
| List information of columns in a table. | |
| 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. | |
| DDLDescTable ($table, $field="") | |
| Return a pointer of line with description of a table or field. | |
| DDLAddField ($table, $field_name, $field_desc, $field_position="") | |
| Create a new field into table. | |
| DDLUpdateField ($table, $field_name, $field_desc) | |
| Update format of a field into a table. | |
| DDLDropField ($table, $field_name) | |
| Drop a field from table. | |
| 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) | |
| getDefaultCharacterSetDatabase () | |
| Return charset used to store data in current database Note: if we are connected to databasename, it is same result than using SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = "databasename";) | |
| getListOfCharacterSet () | |
| Return list of available charset that can be used to store data in database. | |
| getDefaultCollationDatabase () | |
| Return collation used in current database. | |
| getListOfCollation () | |
| Return list of available collation that can be used for database. | |
| getPathOfDump () | |
| Return full path of dump program. | |
| getPathOfRestore () | |
| Return full path of restore program. | |
| getServerParametersValues ($filter='') | |
| Return value of server parameters. | |
| getServerStatusValues ($filter='') | |
| Return value of server status (current indicators on memory, cache...) | |
| getNextAutoIncrementId ($table) | |
| Get the last ID of an auto-increment field of a table. | |
| prepare ($sql) | |
| Prepare a SQL statement for execution. | |
Public Member Functions inherited from DoliDB | |
| 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. | |
| 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 | |
| sanitize ($stringtosanitize) | |
| Sanitize a string for SQL forging. | |
Public Attributes | |
| $type = 'mysqli' | |
| Database type. | |
| const | LABEL = 'MySQL or MariaDB' |
| Database label. | |
| const | VERSIONMIN = '5.0.3' |
| Version min database. | |
Public Attributes inherited from DoliDB | |
| 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. | |
Static Protected Member Functions | |
| static | getCallerInfoString () |
| Get caller info. | |
Class to manage Dolibarr database access for a MySQL database using the MySQLi extension.
Definition at line 36 of file mysqli.class.php.
| DoliDBMysqli::__construct | ( | $type, | |
| $host, | |||
| $user, | |||
| $pass, | |||
| $name = '', | |||
| $port = 0 ) |
Constructor.
This create an opened connection to a database server and eventually to a database
| string | $type | Type of database (mysql, pgsql...). Not used. |
| string | $host | Address of database server |
| string | $user | Name of database user |
| string | $pass | Password of database user |
| string | $name | Name of database |
| int | $port | Port of database server |
Definition at line 62 of file mysqli.class.php.
References $conf, connect(), dol_syslog(), error(), select_db(), and string.
| DoliDBMysqli::affected_rows | ( | $resultset | ) |
Return the number of lines in the result of a request INSERT, DELETE or UPDATE.
| mysqli_result | $resultset | Curseur de la requete voulue |
Implements Database.
Definition at line 494 of file mysqli.class.php.
| DoliDBMysqli::close | ( | ) |
Close database connection.
Implements Database.
Definition at line 307 of file mysqli.class.php.
References dol_syslog().
| DoliDBMysqli::connect | ( | $host, | |
| $login, | |||
| $passwd, | |||
| $name, | |||
| $port = 0 ) |
Connect 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) |
| integer | $port | Port of database server |
Implements Database.
Definition at line 257 of file mysqli.class.php.
References dol_print_error(), and dol_syslog().
Referenced by __construct().
| DoliDBMysqli::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...) |
Implements Database.
Definition at line 219 of file mysqli.class.php.
| DoliDBMysqli::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,extra?:string,null?: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 e.g.: "after some_field" |
Implements Database.
Definition at line 981 of file mysqli.class.php.
| DoliDBMysqli::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 |
Implements Database.
Definition at line 719 of file mysqli.class.php.
| DoliDBMysqli::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<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array<int,string>,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> | $fields Tableau associatif [nom champ][tableau des descriptions] | |
| string | $primary_key | Nom du champ qui sera la clef primaire |
| string | $type | Type de la table |
| ?array<string,mixed> | $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur | |
| string[] | $fulltext_keys | Tableau des Nom de champs qui seront indexes en fulltext |
| array<string,mixed> | $keys Tableau des champs cles noms => valeur |
Implements Database.
Definition at line 848 of file mysqli.class.php.
| DoliDBMysqli::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 | Ip server or '' |
| string | $dolibarr_main_db_user | Nom new user |
| string | $dolibarr_main_db_pass | Password for the new user |
| string | $dolibarr_main_db_name | Database name where user must be granted |
Implements Database.
Definition at line 1114 of file mysqli.class.php.
| DoliDBMysqli::DDLDescTable | ( | $table, | |
| $field = "" ) |
Return a pointer of line with description of a table or field.
| string | $table | Name of table |
| string | $field | Optionnel : Name of field if we want description of field |
Implements Database.
Definition at line 961 of file mysqli.class.php.
| DoliDBMysqli::DDLDropField | ( | $table, | |
| $field_name ) |
Drop a field from table.
| string | $table | Name of table |
| string | $field_name | Name of field to drop |
Implements Database.
Definition at line 1090 of file mysqli.class.php.
| DoliDBMysqli::DDLDropTable | ( | $table | ) |
Drop a table into database.
| string | $table | Name of table |
Implements Database.
Definition at line 939 of file mysqli.class.php.
| DoliDBMysqli::DDLGetConnectId | ( | ) |
Return connection ID.
Implements Database.
Definition at line 695 of file mysqli.class.php.
| DoliDBMysqli::DDLInfoTable | ( | $table | ) |
List information of columns in a table.
| string | $table | Name of table |
Implements Database.
Definition at line 816 of file mysqli.class.php.
| DoliDBMysqli::DDLListTables | ( | $database, | |
| $table = '' ) |
List tables into a database.
| string | $database | Name of database |
| string | $table | Name of table filter ('xxx') |
Implements Database.
Definition at line 753 of file mysqli.class.php.
| DoliDBMysqli::DDLListTablesFull | ( | $database, | |
| $table = '' ) |
List tables into a database.
| string | $database | Name of database |
| string | $table | Name of table filter ('xxx') |
Implements Database.
Definition at line 785 of file mysqli.class.php.
| DoliDBMysqli::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,value?:string,null?:string} | $field_desc Array with description of field format |
Implements Database.
Definition at line 1037 of file mysqli.class.php.
| DoliDBMysqli::decrypt | ( | $value | ) |
Decrypt sensitive data in database.
| string | $value | Value to decrypt |
Implements Database.
Definition at line 665 of file mysqli.class.php.
References $conf.
| DoliDBMysqli::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). |
Implements Database.
Definition at line 636 of file mysqli.class.php.
| DoliDBMysqli::errno | ( | ) |
Return generic error code of last operation.
Implements Database.
Definition at line 552 of file mysqli.class.php.
Referenced by query().
| DoliDBMysqli::error | ( | ) |
Return description of last error.
Implements Database.
Definition at line 604 of file mysqli.class.php.
Referenced by __construct(), and query().
| DoliDBMysqli::escape | ( | $stringtoencode | ) |
Escape a string to insert data.
| string | $stringtoencode | String to escape |
Implements Database.
Definition at line 530 of file mysqli.class.php.
Referenced by encrypt().
| DoliDBMysqli::escapeforlike | ( | $stringtoencode | ) |
Escape a string to insert data into a like.
| string | $stringtoencode | String to escape |
Implements Database.
Definition at line 541 of file mysqli.class.php.
| DoliDBMysqli::fetch_array | ( | $resultset | ) |
Return data as an array.
| mysqli_result | $resultset | Resultset of request |
Implements Database.
Definition at line 436 of file mysqli.class.php.
| DoliDBMysqli::fetch_object | ( | $resultset | ) |
Returns the current line (as an object) for the resultset cursor.
| mysqli_result | $resultset | Curseur de la requete voulue |
Implements Database.
Definition at line 418 of file mysqli.class.php.
| DoliDBMysqli::fetch_row | ( | $resultset | ) |
Return data as an array.
| mysqli_result | $resultset | Resultset of request |
Implements Database.
Definition at line 453 of file mysqli.class.php.
| DoliDBMysqli::free | ( | $resultset = null | ) |
Free the last pointer resultset used by this connection.
| mysqli_result | null | $resultset | Result set of request |
Implements Database.
Definition at line 512 of file mysqli.class.php.
|
staticfinalprotected |
| DoliDBMysqli::getDefaultCharacterSetDatabase | ( | ) |
Return charset used to store data in current database Note: if we are connected to databasename, it is same result than using SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = "databasename";)
Implements Database.
Definition at line 1159 of file mysqli.class.php.
| DoliDBMysqli::getDefaultCollationDatabase | ( | ) |
Return collation used in current database.
Implements Database.
Definition at line 1202 of file mysqli.class.php.
| DoliDBMysqli::getDriverInfo | ( | ) |
Return version of database client driver.
Implements Database.
Definition at line 295 of file mysqli.class.php.
| DoliDBMysqli::getListOfCharacterSet | ( | ) |
Return list of available charset that can be used to store data in database.
Implements Database.
Definition at line 1177 of file mysqli.class.php.
| DoliDBMysqli::getListOfCollation | ( | ) |
Return list of available collation that can be used for database.
Implements Database.
Definition at line 1220 of file mysqli.class.php.
| DoliDBMysqli::getNextAutoIncrementId | ( | $table | ) |
Get the last ID of an auto-increment field of a table.
| string | $table | Name of table |
Reimplemented from DoliDB.
Definition at line 1328 of file mysqli.class.php.
| DoliDBMysqli::getPathOfDump | ( | ) |
Return full path of dump program.
Implements Database.
Definition at line 1243 of file mysqli.class.php.
| DoliDBMysqli::getPathOfRestore | ( | ) |
Return full path of restore program.
Implements Database.
Definition at line 1261 of file mysqli.class.php.
| DoliDBMysqli::getServerParametersValues | ( | $filter = '' | ) |
Return value of server parameters.
| string | $filter | Filter list on a particular value |
Implements Database.
Definition at line 1280 of file mysqli.class.php.
| DoliDBMysqli::getServerStatusValues | ( | $filter = '' | ) |
Return value of server status (current indicators on memory, cache...)
| string | $filter | Filter list on a particular value |
Implements Database.
Definition at line 1304 of file mysqli.class.php.
| DoliDBMysqli::getVersion | ( | ) |
Return version of database server.
Implements Database.
Definition at line 285 of file mysqli.class.php.
| DoliDBMysqli::hintindex | ( | $nameofindex, | |
| $mode = 1 ) |
Return SQL string to force an index.
| string | $nameofindex | Name of index |
| int | $mode | 0=Use, 1=Force |
Reimplemented from DoliDB.
Definition at line 206 of file mysqli.class.php.
| DoliDBMysqli::last_insert_id | ( | $tab, | |
| $fieldid = 'rowid' ) |
Get last ID after an insert INSERT.
| string | $tab | Table name concerned by insert. Use of this could be avoided with MySql as last inset id is stored into the Mysqli object but we use it for compatibility with Postgresql |
| string | $fieldid | Field name |
Implements Database.
Definition at line 622 of file mysqli.class.php.
| DoliDBMysqli::num_rows | ( | $resultset | ) |
Return number of lines for result of a SELECT.
| mysqli_result | $resultset | Resulset of requests |
Implements Database.
Definition at line 476 of file mysqli.class.php.
| DoliDBMysqli::prepare | ( | $sql | ) |
Prepare a SQL statement for execution.
| string | $sql | SQL query to prepare |
Reimplemented from DoliDB.
Definition at line 1350 of file mysqli.class.php.
| DoliDBMysqli::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 (Using 1=MYSQLI_USE_RESULT instead of 0=MYSQLI_STORE_RESULT will not buffer the result and save memory) |
Implements Database.
Definition at line 331 of file mysqli.class.php.
References dol_syslog(), errno(), error(), getDolGlobalInt(), DoliDB\lasterrno(), DoliDB\lasterror(), DoliDB\lastquery(), and DoliDB\lastqueryerror().
| DoliDBMysqli::select_db | ( | $database | ) |
Select a database.
| string | $database | Name of database |
Implements Database.
Definition at line 232 of file mysqli.class.php.
References dol_syslog().
Referenced by __construct().