DoliDBMysqli
class DoliDBMysqli extends DoliDB (View source)
Class to manage Dolibarr database access for a MySQL database using the MySQLi extension
Constants
| VERSIONMIN |
|
| LABEL |
|
Properties
| mysqli | $db | ||
| $type | |||
| string | $forcecharset | from DoliDB | |
| string | $forcecollate | from DoliDB | |
| bool | $connected | from DoliDB | |
| bool | $database_selected | from DoliDB | |
| string | $database_name | from DoliDB | |
| string | $database_user | from DoliDB | |
| string | $database_host | from DoliDB | |
| int | $database_port | from DoliDB | |
| int | $transaction_opened | from DoliDB | |
| string | $lastquery | from DoliDB | |
| string | $lastqueryerror | from DoliDB | |
| string | $lasterror | from DoliDB | |
| string | $lasterrno | from DoliDB | |
| string | $prefix_db | from DoliDB | |
| bool | $ok | from DoliDB | |
| string | $error | from DoliDB |
Methods
Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...).
Return SQL string to aggregate using the Standard Deviation of population
Return SQL string to force an index
Format a SQL REGEXP
Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
Sanitize a string for SQL forging
Define sort criteria of request
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'
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. It should only be used with SELECT queries Don't add LIMIT to your query, it will be added by this method
Return all results from query as an array of objects. Using this is a bad practice and is discouraged.
Get the last ID of an auto-increment field of a table
Prepare a SQL statement for execution
Constructor.
Convert a SQL request in Mysql syntax to native syntax
Select a database
Connect to server
Return version of database server
Return version of database client driver
Close database connection
Execute a SQL request and return the resultset
Get caller info
Returns the current line (as an object) for the resultset cursor
Return number of lines for result of a SELECT
Return the number of lines in the result of a request INSERT, DELETE or UPDATE
Libere le dernier resultset utilise sur cette connection
Escape a string to insert data
Escape a string to insert data into a like
Return generic error code of last operation.
Return description of last error
Get last ID after an insert INSERT
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
Decrypt sensitive data in database
Return connection ID
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
List tables into a database
List tables into a database
List information of columns in a table.
Create a table into database
Drop a table into database
Return a pointer of line with description of a table or field
Create a new field into table
Update format of a field into a table
Drop a field from table
Create a user and privileges to connect to database (even if database does not exists yet)
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";)
Return list of available charset that can be used to store data in database
Return collation used in current database
Return list of available collation that can be used for database
Return full path of dump program
Return full path of restore program
Return value of server parameters
Return value of server status (current indicators on memory, cache...)
Details
in
DoliDB at line 91
string
prefix()
Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...).
Otherwise return MAIN_DB_PREFIX (common use).
string
ifsql(string $test, string $resok, string $resko)
Format a SQL IF
string
stddevpop(string $nameoffield)
Return SQL string to aggregate using the Standard Deviation of population
string
hintindex(string $nameofindex, int $mode = 1)
Return SQL string to force an index
string
regexpsql(string $subject, string $pattern, int $sqlstring = 0)
Format a SQL REGEXP
string
idate(int $param, "gmt"|"tzserver" $gm = 'tzserver')
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
string
lasterrno()
Return last error code
string
sanitize(string $stringtosanitize, int $allowsimplequote = 0, int $allowsequals = 0, int $allowsspace = 0, int $allowschars = 1)
Sanitize a string for SQL forging
int
begin(string $textinlog = '')
Start transaction
int
commit(string $log = '')
Validate a database transaction
int
rollback(string $log = '')
Cancel a transaction and go back to initial data values
@param string $log Add more log to default log line
string
plimit(int $limit = 0, int $offset = 0)
Define limits and offset of request
string[]
getVersionArray()
Return version of database server into an array
string
lastquery()
Return last request executed with query()
string
order(string $sortfield = '', string $sortorder = '')
Define sort criteria of request
string
lasterror()
Return last error label
int|""
jdate(string $string, bool $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'
@param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
string
lastqueryerror()
Return last query in error
bool|int|object
getRow(string $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. It should only be used with SELECT queries Don't add LIMIT to your query, it will be added by this method
false|object[]
getRows(string $sql)
Return all results from query as an array of objects. Using this is a bad practice and is discouraged.
Note : It should only be used with SELECT queries and with a limit. If you are not able to defined/know what can be the limit, it just means this function is not what you need. Do not use it.
int
getNextAutoIncrementId(string $table)
Get the last ID of an auto-increment field of a table
mixed
prepare(string $sql)
Prepare a SQL statement for execution
__construct(string $type, string $host, string $user, string $pass, string $name = '', int $port = 0)
Constructor.
This create an opened connection to a database server and eventually to a database
string
convertSQLFromMysql(string $line, string $type = 'ddl')
Convert a SQL request in Mysql syntax to native syntax
@param string $line SQL request line to convert
bool
select_db(string $database)
Select a database
@param string $database Name of database
false|resource|mysqli|mysqliDoli|Connection|SQLite3
connect(string $host, string $login, string $passwd, string $name, int $port = 0)
Connect to server
string
getVersion()
Return version of database server
string
getDriverInfo()
Return version of database client driver
bool
close()
Close database connection
@return bool True if disconnect successful, false otherwise
bool|mysqli_result|resource
query(string $query, int $usesavepoint = 0, string $type = 'auto', int $result_mode = 0)
Execute a SQL request and return the resultset
@param string $query SQL query string
final static protected string
getCallerInfoString()
Get caller info
object|false
fetch_object(mysqli_result|resource|Connection|SQLite3Result $resultset)
Returns the current line (as an object) for the resultset cursor
array<int|string, mixed>|null|false
fetch_array(mysqli_result|resource|SQLite3Result $resultset)
Return data as an array
array<string|int, mixed>|null|int<0, 0>
fetch_row(mysqli_result|resource|SQLite3Result $resultset)
Return data as an array
int
num_rows(mysqli_result|resource|SQLite3Result $resultset)
Return number of lines for result of a SELECT
int
affected_rows(mysqli_result|resource|SQLite3Result $resultset)
Return the number of lines in the result of a request INSERT, DELETE or UPDATE
void
free(resource|mysqli_result|SQLite3Result $resultset = null)
Libere le dernier resultset utilise sur cette connection
string
escape(string $stringtoencode)
Escape a string to insert data
string
escapeforlike(string $stringtoencode)
Escape a string to insert data into a like
string
errno()
Return generic error code of last operation.
string
error()
Return description of last error
int
last_insert_id(string $tab, string $fieldid = 'rowid')
Get last ID after an insert INSERT
string
encrypt(string $fieldorvalue, int $withQuotes = 1)
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
string
decrypt(string $value)
Decrypt sensitive data in database
string
DDLGetConnectId()
Return connection ID
bool|SQLite3Result|mysqli_result|resource
DDLCreateDb(string $database, string $charset = '', string $collation = '', string $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, string $table = '')
List tables into a database
@param string $database Name of database
DDLListTablesFull($database, string $table = '')
List tables into a database
@param string $database Name of database
array<array<string, mixed>>
DDLInfoTable(string $table)
List information of columns in a table.
int
DDLCreateTable(string $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, string $primary_key, string $type, ?array<string, mixed> $unique_keys = null, string[] $fulltext_keys = null, string[] $keys = null)
Create a table into database
int
DDLDropTable(string $table)
Drop a table into database
bool|resource|mysqli_result|SQLite3Result
DDLDescTable(string $table, string $field = "")
Return a pointer of line with description of a table or field
int
DDLAddField(string $table, string $field_name, 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, string $field_position = "")
Create a new field into table
int
DDLUpdateField(string $table, string $field_name, 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)
Update format of a field into a table
int
DDLDropField(string $table, string $field_name)
Drop a field from table
int
DDLCreateUser(string $dolibarr_main_db_host, string $dolibarr_main_db_user, string $dolibarr_main_db_pass, string $dolibarr_main_db_name)
Create a user and privileges to connect to database (even if database does not exists yet)
string
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";)
?array<int, array{charset: string, description: string}>
getListOfCharacterSet()
Return list of available charset that can be used to store data in database
string
getDefaultCollationDatabase()
Return collation used in current database
?array<int, array{collation: string}>
getListOfCollation()
Return list of available collation that can be used for database
string
getPathOfDump()
Return full path of dump program
string
getPathOfRestore()
Return full path of restore program
array<string, string>
getServerParametersValues(string $filter = '')
Return value of server parameters
array<string, string>
getServerStatusValues(string $filter = '')
Return value of server status (current indicators on memory, cache...)