TraceableDB
class TraceableDB extends DoliDB (View source)
TraceableDB class
Used to log queries into DebugBar
Constants
| VERSIONMIN |
|
| LABEL |
|
Properties
| DoliDB | $db | ||
| string | $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 | |
| array<array<string, null|true|string>> | $queries | ||
| protected float | $startTime | ||
| protected int | $startMemory |
Methods
Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...).
Format a SQL IF
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.
Return last error code
Sanitize a string for SQL forging
Start transaction
Validate a database transaction
Cancel a transaction and go back to initial data values
Define limits and offset of request
Return version of database server into an array
Return last request executed with query()
Define sort criteria of request
Return last error label
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 whatever is TZ if gmt=1
Return last query in error
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
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
Convert a SQL request in Mysql syntax to native syntax
Return the number o flines into the result of a request INSERT, DELETE or UPDATE
Return description of last error
List tables into a database
List tables into a database with table info
Decrypt sensitive data in database
Escape a string to insert data
Escape a string to insert data into a like
Get last ID after an insert INSERT
Return full path of restore program
Execute a SQL request and return the resultset
Start query tracing
End query tracing
Connection to server
Return value of server parameters
Return value of server status
Return collation used in database
Return number of lines for result of a SELECT
Return full path of dump program
Return version of database client driver
Return generic error code of last operation.
Create a table into database
Drop a table into database
Return list of available charset that can be used to store data in database
Create a new field into table
Drop a field from table
Update format of a field into a table
Return list of available collation that can be used for database
Return a pointer of line with description of a table or field
Return version of database server
Return charset used to store data in database
Create a user and privileges to connect to database (even if database does not exists yet)
Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
List information of columns into a table.
Close database connection
Return connection ID
Returns the current line (as an object) for the resultset cursor
Select a database
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 = null, string $sortorder = null)
Define sort criteria of request
string
lasterror()
Return last error label
int|""
jdate(string $string, bool $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 whatever is TZ if gmt=1
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
This method must be implemented by subclasses.
__construct(DoliDB $db)
Constructor
array<string|int, mixed>|null|int<0, 0>
fetch_row(mysqli_result|resource|SQLite3Result $resultset)
Return datas as an array
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
string
convertSQLFromMysql(string $line, string $type = 'ddl')
Convert a SQL request in Mysql syntax to native syntax
int
affected_rows(mysqli_result|resource|SQLite3Result $resultset)
Return the number o flines into the result of a request INSERT, DELETE or UPDATE
string
error()
Return description of last error
DDLListTables($database, string $table = '')
List tables into a database
@param string $database Name of database
DDLListTablesFull($database, string $table = '')
List tables into a database with table info
@param string $database Name of database
string
decrypt(string $value)
Decrypt sensitive data in database
array<int|string, mixed>|null|false
fetch_array(mysqli_result|resource|SQLite3Result $resultset)
Return datas as an array
string
escape(string $stringtoencode)
Escape a string to insert data
string
escapeforlike(string $stringtoencode)
Escape a string to insert data into a like
int
last_insert_id(string $tab, string $fieldid = 'rowid')
Get last ID after an insert INSERT
string
getPathOfRestore()
Return full path of restore program
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
protected void
startTracing()
Start query tracing
protected void
endTracing(string $sql, mysqli_result|bool|resource $resql)
End query tracing
false|resource|mysqli|mysqliDoli|Connection|SQLite3
connect(string $host, string $login, string $passwd, string $name, int $port = 0)
Connection to server
array<string, string>
getServerParametersValues(string $filter = '')
Return value of server parameters
array<string, string>
getServerStatusValues(string $filter = '')
Return value of server status
string
getDefaultCollationDatabase()
Return collation used in database
int
num_rows(mysqli_result|resource|SQLite3Result $resultset)
Return number of lines for result of a SELECT
string
getPathOfDump()
Return full path of dump program
string
getDriverInfo()
Return version of database client driver
string
errno()
Return generic error code of last operation.
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
?array<int, array{charset: string, description: string}>
getListOfCharacterSet()
Return list of available charset that can be used to store data in database
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
DDLDropField(string $table, string $field_name)
Drop a field from 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
?array<int, array{collation: string}>
getListOfCollation()
Return list of available collation that can be used for database
bool|resource|mysqli_result|SQLite3Result
DDLDescTable(string $table, string $field = "")
Return a pointer of line with description of a table or field
string
getVersion()
Return version of database server
string
getDefaultCharacterSetDatabase()
Return charset used to store data in database
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
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.
array<array<string, mixed>>
DDLInfoTable(string $table)
List information of columns into a table.
void
free(resource|mysqli_result|SQLite3Result $resultset = null)
Free last resultset used.
bool
close()
Close database connection
string
DDLGetConnectId()
Return connection ID
object|false
fetch_object(mysqli_result|resource|Connection|SQLite3Result $resultset)
Returns the current line (as an object) for the resultset cursor
bool
select_db(string $database)
Select a database