dolibarr  7.0.0-beta
Public Member Functions | Static Public Member Functions | List of all members
Database Interface Reference

Class to manage Dolibarr database access for an SQL database. More...

+ Inheritance diagram for Database:

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 ()
 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)
 Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou 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...
 
 last_insert_id ($tab, $fieldid= 'rowid')
 Get last ID after an insert INSERT. More...
 
 getPathOfRestore ()
 Return full path of restore program. More...
 
 rollback ($log= '')
 Annulation d'une transaction et retour aux anciennes valeurs. More...
 
 query ($query, $usesavepoint=0, $type= 'auto')
 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=0)
 Encrypt sensitive data in database Warning: This function includes the escape, so it must use direct value. 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)
 Renvoie la ligne courante (comme un objet) pour le curseur resultset. 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...
 

Detailed Description

Class to manage Dolibarr database access for an SQL database.

Definition at line 26 of file Database.interface.php.

Member Function Documentation

Database::affected_rows (   $resultset)

Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE.

Parameters
resource$resultsetCurseur de la requete voulue
Returns
int Nombre de lignes
See also
num_rows

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::begin ( )

Start transaction.

Returns
int 1 if transaction successfuly opened or already opened, 0 if error

Implemented in DoliDBMssql, and DoliDB.

Database::close ( )

Close database connexion.

Returns
boolean True if disconnect successfull, false otherwise
See also
connect

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMysqli, and DoliDBMssql.

Database::commit (   $log = '')

Validate a database transaction.

Parameters
string$logAdd more log to default log line
Returns
int 1 if validation is OK or transaction level no started, 0 if ERROR

Implemented in DoliDBMssql, and DoliDB.

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

Connexion to server.

Parameters
string$hostdatabase server host
string$loginlogin
string$passwdpassword
string$namename of database (not used for mysql, used for pgsql)
int$portPort of database server
Returns
resource Database access handler
See also
close

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMysqli, and DoliDBMssql.

static Database::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

Implemented in DoliDBMysqli, DoliDBMssql, and DoliDBSqlite3.

Database::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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, 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.

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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, 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)

Parameters
string$dolibarr_main_db_hostIp serveur
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

Implemented in DoliDBSqlite3, DoliDBPgsql, DoliDBMssql, and DoliDBMysqli.

Database::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
resource Resource

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::DDLDropTable (   $table)

Drop a table into database.

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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::DDLGetConnectId ( )

Return connexion ID.

Returns
string Id connexion

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::DDLInfoTable (   $table)

List information of columns into a table.

Parameters
string$tableName of table
Returns
array Array with inforation on table

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::decrypt (   $value)

Decrypt sensitive data in database.

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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::encrypt (   $fieldorvalue,
  $withQuotes = 0 
)

Encrypt sensitive data in database Warning: This function includes the escape, so it must use direct value.

Parameters
string$fieldorvalueField name or value to encrypt
int$withQuotesReturn string with quotes
Returns
string XXX(field) or XXX('value') or field or 'value'

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::errno ( )

Return generic error code of last operation.

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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::error ( )

Return description of last error.

Returns
string Error text

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::escape (   $stringtoencode)

Escape a string to insert data.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::fetch_array (   $resultset)

Return datas as an array.

Parameters
resource$resultsetResultset of request
Returns
array Array

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::fetch_object (   $resultset)

Renvoie la ligne courante (comme un objet) pour le curseur resultset.

Parameters
resource$resultsetCurseur de la requete voulue
Returns
Object Object result line or false if KO or end of cursor

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Referenced by Societe\replaceThirdparty().

Database::fetch_row (   $resultset)

Return datas as an array.

Parameters
resource$resultsetResultset of request
Returns
array Array

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::free (   $resultset = null)

Free last resultset used.

Parameters
resource$resultsetFre cursor
Returns
void

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getDefaultCharacterSetDatabase ( )

Return charset used to store data in database.

Returns
string Charset

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getDefaultCollationDatabase ( )

Return collation used in database.

Returns
string Collation value

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getDriverInfo ( )

Return version of database client driver.

Returns
string Version string

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMysqli, and DoliDBMssql.

Database::getListOfCharacterSet ( )

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

Returns
array List of Charset

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getListOfCollation ( )

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

Returns
array List of Collation

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getPathOfDump ( )

Return full path of dump program.

Returns
string Full path of dump program

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getPathOfRestore ( )

Return full path of restore program.

Returns
string Full path of restore program

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getServerParametersValues (   $filter = '')

Return value of server parameters.

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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getServerStatusValues (   $filter = '')

Return value of server status.

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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::getVersion ( )

Return version of database server.

Returns
string Version string

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMysqli, and DoliDBMssql.

Referenced by DoliDB\getVersionArray().

Database::getVersionArray ( )

Return version of database server into an array.

Returns
array Version array

Implemented in 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

Parameters
int$paramDate TMS to convert
Returns
string Date in a string YYYYMMDDHHMMSS

Implemented in DoliDBPgsql, DoliDBMssql, and DoliDB.

Database::ifsql (   $test,
  $resok,
  $resko 
)

Format a SQL IF.

Parameters
string$testTest string (example: 'cd.statut=0', 'field IS NULL')
string$resokresultat si test egal
string$reskoresultat si test non egal
Returns
string SQL string

Implemented in 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.

Parameters
string$stringDate in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
bool$gm1=Input informations are GMT values, otherwise local to server TZ
Returns
int|string Date TMS or ''

Implemented in DoliDB.

Database::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 Id of row

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::lasterrno ( )

Return last error code.

Returns
string lasterrno

Implemented in DoliDB.

Database::lasterror ( )

Return last error label.

Returns
string lasterror

Implemented in DoliDB.

Database::lastquery ( )

Return last request executed with query()

Returns
string Last query

Implemented in DoliDB.

Database::lastqueryerror ( )

Return last query in error.

Returns
string lastqueryerror

Implemented in DoliDB.

Database::num_rows (   $resultset)

Return number of lines for result of a SELECT.

Parameters
resource$resultsetResulset of requests
Returns
int Nb of lines
See also
affected_rows

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Database::order (   $sortfield = null,
  $sortorder = null 
)

Define sort criteria of request.

Parameters
string$sortfieldList of sort fields
string$sortorderSort order
Returns
string String to provide syntax of a sort sql string

Implemented in DoliDB.

Database::plimit (   $limit = 0,
  $offset = 0 
)

Define limits and offset of request.

Parameters
int$limitMaximum number of lines returned (-1=conf->liste_limit, 0=no limit)
int$offsetNumero of line from where starting fetch
Returns
string String with SQL syntax to add a limit and offset

Implemented in DoliDBPgsql, and DoliDB.

Database::query (   $query,
  $usesavepoint = 0,
  $type = 'auto' 
)

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...)
Returns
resource Resultset of answer

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMssql, and DoliDBMysqli.

Referenced by DoliDB\begin(), DoliDB\commit(), Societe\replaceThirdparty(), and DoliDB\rollback().

Database::rollback (   $log = '')

Annulation d'une transaction et retour aux anciennes valeurs.

Parameters
string$logAdd more log to default log line
Returns
int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur

Implemented in DoliDBMssql, and DoliDB.

Database::select_db (   $database)

Select a database.

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

Implemented in DoliDBPgsql, DoliDBSqlite3, DoliDBMysqli, and DoliDBMssql.


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