dolibarr  17.0.4
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
DoliDBMysqli Class Reference

Class to manage Dolibarr database access for a MySQL database using the MySQLi extension. More...

Inheritance diagram for DoliDBMysqli:
Inheritance graph
[legend]
Collaboration diagram for DoliDBMysqli:
Collaboration graph
[legend]

Public Member Functions

 __construct ($type, $host, $user, $pass, $name='', $port=0)
 Constructor. More...
 
 hintindex ($nameofindex)
 Return SQL string to force an index. More...
 
 select_db ($database)
 Select a database. More...
 
 connect ($host, $login, $passwd, $name, $port=0)
 Connect to server. More...
 
 getVersion ()
 Return version of database server. More...
 
 getDriverInfo ()
 Return version of database client driver. More...
 
 close ()
 Close database connexion. More...
 
 query ($query, $usesavepoint=0, $type='auto', $result_mode=0)
 Execute a SQL request and return the resultset. More...
 
 fetch_object ($resultset)
 Returns the current line (as an object) for the resultset cursor. More...
 
 fetch_array ($resultset)
 Return datas as an array. More...
 
 fetch_row ($resultset)
 Return datas as an array. More...
 
 num_rows ($resultset)
 Return number of lines for result of a SELECT. More...
 
 affected_rows ($resultset)
 Return the number of lines in the result of a request INSERT, DELETE or UPDATE. More...
 
 free ($resultset=null)
 Libere le dernier resultset utilise sur cette connexion. More...
 
 escape ($stringtoencode)
 Escape a string to insert data. More...
 
 escapeunderscore ($stringtoencode)
 Escape a string to insert data. More...
 
 escapeforlike ($stringtoencode)
 Escape a string to insert data into a like. More...
 
 errno ()
 Return generic error code of last operation. More...
 
 error ()
 Return description of last error. More...
 
 last_insert_id ($tab, $fieldid='rowid')
 Get last ID after an insert INSERT. 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...
 
 decrypt ($value)
 Decrypt sensitive data in database. More...
 
 DDLGetConnectId ()
 Return connexion ID. 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...
 
 DDLListTables ($database, $table='')
 List tables into a database. More...
 
 DDLInfoTable ($table)
 List information of columns into a table. 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...
 
 DDLDescTable ($table, $field="")
 Return a pointer of line with description of a table or field. More...
 
 DDLAddField ($table, $field_name, $field_desc, $field_position="")
 Create a new field into table. More...
 
 DDLUpdateField ($table, $field_name, $field_desc)
 Update format of a field into a table. More...
 
 DDLDropField ($table, $field_name)
 Drop a field from table. 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...
 
 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";) More...
 
 getListOfCharacterSet ()
 Return list of available charset that can be used to store data in database. More...
 
 getDefaultCollationDatabase ()
 Return collation used in current database. More...
 
 getListOfCollation ()
 Return list of available collation that can be used for database. More...
 
 getPathOfDump ()
 Return full path of dump program. More...
 
 getPathOfRestore ()
 Return full path of restore program. More...
 
 getServerParametersValues ($filter='')
 Return value of server parameters. More...
 
 getServerStatusValues ($filter='')
 Return value of server status (current indicators on memory, cache...) More...
 
- Public Member Functions inherited from DoliDB
 prefix ()
 Return the DB prefix. More...
 
 ifsql ($test, $resok, $resko)
 Format a SQL IF. More...
 
 regexpsql ($subject, $pattern, $sqlstring=false)
 Format a SQL REGEXP. More...
 
 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. More...
 
 lasterrno ()
 Return last error code. More...
 
 sanitize ($stringtosanitize, $allowsimplequote=0, $allowsequals=0)
 Sanitize a string for SQL forging. More...
 
 begin ($textinlog='')
 Start transaction. More...
 
 commit ($log='')
 Validate a database transaction. More...
 
 rollback ($log='')
 Cancel a transaction and go back to initial data values. More...
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request. More...
 
 getVersionArray ()
 Return version of database server into an array. More...
 
 lastquery ()
 Return last request executed with query() More...
 
 order ($sortfield=null, $sortorder=null)
 Define sort criteria of request. More...
 
 lasterror ()
 Return last error label. More...
 
 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 whaterver is server TZ if $gm='gmt'. More...
 
 lastqueryerror ()
 Return last query in error. More...
 
 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. More...
 
 getRows ($sql)
 Return all results from query as an array of objects Note : This method executes a given SQL query and retrieves all row of results as an array of objects. More...
 
- Public Member Functions inherited from Database
 idate ($param)
 Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. More...
 
 sanitize ($stringtosanitize)
 Sanitize a string for SQL forging. More...
 

Static Public Member Functions

static convertSQLFromMysql ($line, $type='ddl')
 Convert a SQL request in Mysql syntax to native syntax. More...
 

Public Attributes

 $type = 'mysqli'
 Database type.
 
const LABEL = 'MySQL or MariaDB'
 Database label.
 
const VERSIONMIN = '5.0.3'
 Version min database.
 

Detailed Description

Class to manage Dolibarr database access for a MySQL database using the MySQLi extension.

Definition at line 33 of file mysqli.class.php.

Constructor & Destructor Documentation

◆ __construct()

DoliDBMysqli::__construct (   $type,
  $host,
  $user,
  $pass,
  $name = '',
  $port = 0 
)

Constructor.

This create an opened connexion to a database server and eventually to a database

Parameters
string$typeType of database (mysql, pgsql...)
string$hostAddress of database server
string$userNom de l'utilisateur autorise
string$passMot de passe
string$nameNom de la database
int$portPort of database server

Definition at line 57 of file mysqli.class.php.

Member Function Documentation

◆ affected_rows()

DoliDBMysqli::affected_rows (   $resultset)

Return the number of lines in the result of a request INSERT, DELETE or UPDATE.

Parameters
mysqli_result$resultsetCurseur de la requete voulue
Returns
int Number of lines
See also
num_rows()

Implements Database.

Definition at line 435 of file mysqli.class.php.

References db.

◆ close()

DoliDBMysqli::close ( )

Close database connexion.

Returns
bool True if disconnect successfull, false otherwise
See also
connect()

Implements Database.

Definition at line 273 of file mysqli.class.php.

References db, and dol_syslog().

◆ connect()

DoliDBMysqli::connect (   $host,
  $login,
  $passwd,
  $name,
  $port = 0 
)

Connect to server.

Parameters
string$hostDatabase server host
string$loginLogin
string$passwdPassword
string$nameName of database (not used for mysql, used for pgsql)
integer$portPort of database server
Returns
mysqli|null Database access object
See also
close()

Implements Database.

Definition at line 228 of file mysqli.class.php.

◆ convertSQLFromMysql()

static DoliDBMysqli::convertSQLFromMysql (   $line,
  $type = 'ddl' 
)
static

Convert a SQL request in Mysql syntax to native syntax.

Parameters
string$lineSQL request line to convert
string$typeType of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
Returns
string SQL request line converted

Implements Database.

Definition at line 190 of file mysqli.class.php.

◆ DDLAddField()

DoliDBMysqli::DDLAddField (   $table,
  $field_name,
  $field_desc,
  $field_position = "" 
)

Create a new field into table.

Parameters
string$tableName of table
string$field_nameName of field to add
string$field_descTableau associatif de description du champ a inserer[nom du parametre][valeur du parametre]
string$field_positionOptionnel ex.: "after champtruc"
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 891 of file mysqli.class.php.

◆ DDLCreateDb()

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.

Parameters
string$databaseDatabase name to create
string$charsetCharset used to store data
string$collationCharset used to sort data
string$ownerUsername of database owner
Returns
bool|mysqli_result resource defined if OK, null if KO

Implements Database.

Definition at line 672 of file mysqli.class.php.

◆ DDLCreateTable()

DoliDBMysqli::DDLCreateTable (   $table,
  $fields,
  $primary_key,
  $type,
  $unique_keys = null,
  $fulltext_keys = null,
  $keys = null 
)

Create a table into database.

Parameters
string$tableName of table
array$fieldsTableau associatif [nom champ][tableau des descriptions]
string$primary_keyNom du champ qui sera la clef primaire
string$typeType de la table
array$unique_keysTableau associatifs Nom de champs qui seront clef unique => valeur
array$fulltext_keysTableau des Nom de champs qui seront indexes en fulltext
array$keysTableau des champs cles noms => valeur
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 768 of file mysqli.class.php.

◆ DDLCreateUser()

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)

Parameters
string$dolibarr_main_db_hostIp server or ''
string$dolibarr_main_db_userNom user a creer
string$dolibarr_main_db_passMot de passe user a creer
string$dolibarr_main_db_nameDatabase name where user must be granted
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 1006 of file mysqli.class.php.

◆ DDLDescTable()

DoliDBMysqli::DDLDescTable (   $table,
  $field = "" 
)

Return a pointer of line with description of a table or field.

Parameters
string$tableName of table
string$fieldOptionnel : Name of field if we want description of field
Returns
bool|mysqli_result Resultset x (x->Field, x->Type, ...)

Implements Database.

Definition at line 871 of file mysqli.class.php.

◆ DDLDropField()

DoliDBMysqli::DDLDropField (   $table,
  $field_name 
)

Drop a field from table.

Parameters
string$tableName of table
string$field_nameName of field to drop
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 982 of file mysqli.class.php.

◆ DDLDropTable()

DoliDBMysqli::DDLDropTable (   $table)

Drop a table into database.

Parameters
string$tableName of table
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 849 of file mysqli.class.php.

◆ DDLGetConnectId()

DoliDBMysqli::DDLGetConnectId ( )

Return connexion ID.

Returns
string Id connexion

Implements Database.

Definition at line 648 of file mysqli.class.php.

◆ DDLInfoTable()

DoliDBMysqli::DDLInfoTable (   $table)

List information of columns into a table.

Parameters
string$tableName of table
Returns
array Tableau des informations des champs de la table

Implements Database.

Definition at line 736 of file mysqli.class.php.

◆ DDLListTables()

DoliDBMysqli::DDLListTables (   $database,
  $table = '' 
)

List tables into a database.

Parameters
string$databaseName of database
string$tableNmae of table filter ('xxx')
Returns
array List of tables in an array

Implements Database.

Definition at line 705 of file mysqli.class.php.

◆ DDLUpdateField()

DoliDBMysqli::DDLUpdateField (   $table,
  $field_name,
  $field_desc 
)

Update format of a field into a table.

Parameters
string$tableName of table
string$field_nameName of field to modify
string$field_descArray with description of field format
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 937 of file mysqli.class.php.

◆ decrypt()

DoliDBMysqli::decrypt (   $value)

Decrypt sensitive data in database.

Parameters
string$valueValue to decrypt
Returns
string Decrypted value if used

Implements Database.

Definition at line 618 of file mysqli.class.php.

◆ encrypt()

DoliDBMysqli::encrypt (   $fieldorvalue,
  $withQuotes = 1 
)

Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.

Parameters
string$fieldorvalueField name or value to encrypt
int$withQuotesReturn string including the SQL simple quotes. This param must always be 1 (Value 0 is bugged and deprecated).
Returns
string XXX(field) or XXX('value') or field or 'value'

Implements Database.

Definition at line 589 of file mysqli.class.php.

◆ errno()

DoliDBMysqli::errno ( )

Return generic error code of last operation.

Returns
string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...)

Implements Database.

Definition at line 505 of file mysqli.class.php.

◆ error()

DoliDBMysqli::error ( )

Return description of last error.

Returns
string Error text

Implements Database.

Definition at line 557 of file mysqli.class.php.

References db.

◆ escape()

DoliDBMysqli::escape (   $stringtoencode)

Escape a string to insert data.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

Definition at line 472 of file mysqli.class.php.

References db.

◆ escapeforlike()

DoliDBMysqli::escapeforlike (   $stringtoencode)

Escape a string to insert data into a like.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

Definition at line 495 of file mysqli.class.php.

◆ escapeunderscore()

DoliDBMysqli::escapeunderscore (   $stringtoencode)

Escape a string to insert data.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped
Deprecated:

Implements Database.

Definition at line 484 of file mysqli.class.php.

◆ fetch_array()

DoliDBMysqli::fetch_array (   $resultset)

Return datas as an array.

Parameters
mysqli_result$resultsetResultset of request
Returns
array|null Array or null if KO or end of cursor

Implements Database.

Definition at line 377 of file mysqli.class.php.

◆ fetch_object()

DoliDBMysqli::fetch_object (   $resultset)

Returns the current line (as an object) for the resultset cursor.

Parameters
mysqli_result$resultsetCurseur de la requete voulue
Returns
object|null Object result line or null if KO or end of cursor

Implements Database.

Definition at line 359 of file mysqli.class.php.

◆ fetch_row()

DoliDBMysqli::fetch_row (   $resultset)

Return datas as an array.

Parameters
mysqli_result$resultsetResultset of request
Returns
array|null|int Array or null if KO or end of cursor or 0 if resultset is bool

Implements Database.

Definition at line 394 of file mysqli.class.php.

◆ free()

DoliDBMysqli::free (   $resultset = null)

Libere le dernier resultset utilise sur cette connexion.

Parameters
mysqli_result$resultsetCurseur de la requete voulue
Returns
void

Implements Database.

Definition at line 454 of file mysqli.class.php.

◆ getDefaultCharacterSetDatabase()

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";)

Returns
string Charset
See also
getDefaultCollationDatabase()

Implements Database.

Definition at line 1051 of file mysqli.class.php.

◆ getDefaultCollationDatabase()

DoliDBMysqli::getDefaultCollationDatabase ( )

Return collation used in current database.

Returns
string Collation value
See also
getDefaultCharacterSetDatabase()

Implements Database.

Definition at line 1094 of file mysqli.class.php.

References $resql, and query().

◆ getDriverInfo()

DoliDBMysqli::getDriverInfo ( )

Return version of database client driver.

Returns
string Version string

Implements Database.

Definition at line 261 of file mysqli.class.php.

References db.

◆ getListOfCharacterSet()

DoliDBMysqli::getListOfCharacterSet ( )

Return list of available charset that can be used to store data in database.

Returns
array|null List of Charset

Implements Database.

Definition at line 1069 of file mysqli.class.php.

References $resql, and query().

◆ getListOfCollation()

DoliDBMysqli::getListOfCollation ( )

Return list of available collation that can be used for database.

Returns
array|null Liste of Collation

Implements Database.

Definition at line 1112 of file mysqli.class.php.

References $resql, and query().

◆ getPathOfDump()

DoliDBMysqli::getPathOfDump ( )

Return full path of dump program.

Returns
string Full path of dump program

Implements Database.

Definition at line 1135 of file mysqli.class.php.

References $resql, and query().

◆ getPathOfRestore()

DoliDBMysqli::getPathOfRestore ( )

Return full path of restore program.

Returns
string Full path of restore program

Implements Database.

Definition at line 1153 of file mysqli.class.php.

References $resql, and query().

◆ getServerParametersValues()

DoliDBMysqli::getServerParametersValues (   $filter = '')

Return value of server parameters.

Parameters
string$filterFilter list on a particular value
Returns
array Array of key-values (key=>value)

Implements Database.

Definition at line 1172 of file mysqli.class.php.

◆ getServerStatusValues()

DoliDBMysqli::getServerStatusValues (   $filter = '')

Return value of server status (current indicators on memory, cache...)

Parameters
string$filterFilter list on a particular value
Returns
array Array of key-values (key=>value)

Implements Database.

Definition at line 1196 of file mysqli.class.php.

◆ getVersion()

DoliDBMysqli::getVersion ( )

Return version of database server.

Returns
string Version string

Implements Database.

Definition at line 251 of file mysqli.class.php.

References db.

◆ hintindex()

DoliDBMysqli::hintindex (   $nameofindex)

Return SQL string to force an index.

Parameters
string$nameofindexName of index
Returns
string SQL string

Reimplemented from DoliDB.

Definition at line 177 of file mysqli.class.php.

◆ last_insert_id()

DoliDBMysqli::last_insert_id (   $tab,
  $fieldid = 'rowid' 
)

Get last ID after an insert INSERT.

Parameters
string$tabTable name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql
string$fieldidField name
Returns
int|string Id of row

Implements Database.

Definition at line 575 of file mysqli.class.php.

◆ num_rows()

DoliDBMysqli::num_rows (   $resultset)

Return number of lines for result of a SELECT.

Parameters
mysqli_result$resultsetResulset of requests
Returns
int Nb of lines
See also
affected_rows()

Implements Database.

Definition at line 417 of file mysqli.class.php.

◆ query()

bool mysqli_result Resultset of last DoliDBMysqli::query (   $query,
  $usesavepoint = 0,
  $type = 'auto',
  $result_mode = 0 
)

Execute a SQL request and return the resultset.

Parameters
string$querySQL query string
int$usesavepoint0=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$typeType of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
int$result_modeResult mode (Using 1=MYSQLI_USE_RESULT instead of 0=MYSQLI_STORE_RESULT will not buffer the result and save memory)
Returns
bool|mysqli_result Resultset of answer

Implements Database.

Definition at line 297 of file mysqli.class.php.

Referenced by getDefaultCollationDatabase(), getListOfCharacterSet(), getListOfCollation(), getPathOfDump(), and getPathOfRestore().

◆ select_db()

DoliDBMysqli::select_db (   $database)

Select a database.

Parameters
string$databaseName of database
Returns
boolean true if OK, false if KO

Implements Database.

Definition at line 203 of file mysqli.class.php.

References dol_syslog().


The documentation for this class was generated from the following file: