Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mariadb_native_moodle_database Class Reference

Native MariaDB class representing moodle database interface. More...

Inheritance diagram for mariadb_native_moodle_database:
mysqli_native_moodle_database moodle_database

Public Member Functions

 change_database_structure ($sql, $tablenames=null)
 Do NOT use in code, to be used by database_manager only! More...
 
 change_db_encoding ()
 Attempts to change db encoding to UTF-8 encoding if possible. More...
 
 commit_delegated_transaction (moodle_transaction $transaction)
 Indicates delegated transaction finished successfully. More...
 
 connect ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null)
 Connect to db Must be called before other methods. More...
 
 convert_table_row_format ($tablename)
 Converts a table to either 'Compressed' or 'Dynamic' row format. More...
 
 count_records ($table, array $conditions=null)
 Count the records in a table where all the given conditions met. More...
 
 count_records_select ($table, $select, array $params=null, $countitem="COUNT('x')")
 Count the records in a table which match a particular WHERE clause. More...
 
 count_records_sql ($sql, array $params=null)
 Get the result of a SQL SELECT COUNT(...) query. More...
 
 create_database ($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null)
 Attempt to create the database. More...
 
 delete_records ($table, array $conditions=null)
 Delete the records from a table where all the given conditions met. More...
 
 delete_records_list ($table, $field, array $values)
 Delete the records from a table where one field match one list of values. More...
 
 delete_records_select ($table, $select, array $params=null)
 Delete one or more records from a table which match a particular WHERE clause. More...
 
 delete_records_subquery (string $table, string $field, string $alias, string $subquery, array $params=[])
 Deletes records using a subquery, which is done with a strange DELETE...JOIN syntax in MySQL because it performs very badly with normal subqueries. More...
 
 diagnose ()
 Diagnose database and tables, this function is used to verify database and driver settings, db engine types, etc. More...
 
 dispose ()
 Close database connection and release all resources and memory (especially circular memory references). More...
 
 driver_installed ()
 Detects if all needed PHP stuff installed. More...
 
 execute ($sql, array $params=null)
 Execute general sql query. More...
 
 export_dbconfig ()
 Returns the db related part of config.php. More...
 
 export_table_recordset ($table)
 Get all records from a table. More...
 
 fix_sql_params ($sql, array $params=null)
 Normalizes sql query parameters and verifies parameters. More...
 
 force_transaction_rollback ()
 Force rollback of all delegated transaction. More...
 
 get_columns ($table, $usecache=true)
 Returns detailed information about columns in table. More...
 
 get_configuration_help ()
 Returns localised database configuration help. More...
 
 get_configuration_hints ()
 Returns the localised database description Note: can be used before connect() More...
 
 get_dbcollation ()
 Returns the current MySQL db collation. More...
 
 get_dbengine ()
 Returns the current MySQL db engine. More...
 
 get_dbfamily ()
 Returns database family type - describes SQL dialect Note: can be used before connect() More...
 
 get_dbvendor ()
 Returns the database vendor. More...
 
 get_debug ()
 Returns debug status. More...
 
 get_field ($table, $return, array $conditions, $strictness=IGNORE_MISSING)
 Get a single field value from a table record where all the given conditions met. More...
 
 get_field_select ($table, $return, $select, array $params=null, $strictness=IGNORE_MISSING)
 Get a single field value from a table record which match a particular WHERE clause. More...
 
 get_field_sql ($sql, array $params=null, $strictness=IGNORE_MISSING)
 Get a single field value (first field) using a SQL statement. More...
 
 get_fieldset_select ($table, $return, $select, array $params=null)
 Selects records and return values of chosen field as an array which match a particular WHERE clause. More...
 
 get_fieldset_sql ($sql, array $params=null)
 Selects records and return values (first field) as an array using a SQL statement. More...
 
 get_in_or_equal ($items, $type=SQL_PARAMS_QM, $prefix='param', $equal=true, $onemptyitems=false)
 Constructs 'IN()' or '=' sql fragment. More...
 
 get_indexes ($table)
 Return table indexes - everything lowercased. More...
 
 get_last_error ()
 Returns last error reported by database engine. More...
 
 get_manager ()
 Returns the sql generator used for db manipulation. More...
 
 get_name ()
 Returns localised database type name Note: can be used before connect() More...
 
 get_prefix ()
 Returns database table prefix Note: can be used before connect() More...
 
 get_record ($table, array $conditions, $fields=' *', $strictness=IGNORE_MISSING)
 Get a single database record as an object where all the given conditions met. More...
 
 get_record_select ($table, $select, array $params=null, $fields=' *', $strictness=IGNORE_MISSING)
 Get a single database record as an object which match a particular WHERE clause. More...
 
 get_record_sql ($sql, array $params=null, $strictness=IGNORE_MISSING)
 Get a single database record as an object using a SQL statement. More...
 
 get_records ($table, array $conditions=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get a number of records as an array of objects where all the given conditions met. More...
 
 get_records_list ($table, $field, array $values, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get a number of records as an array of objects where one field match one list of values. More...
 
 get_records_menu ($table, array $conditions=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get the first two columns from a number of records as an associative array where all the given conditions met. More...
 
 get_records_select ($table, $select, array $params=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get a number of records as an array of objects which match a particular WHERE clause. More...
 
 get_records_select_menu ($table, $select, array $params=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get the first two columns from a number of records as an associative array which match a particular WHERE clause. More...
 
 get_records_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 Get a number of records as an array of objects using a SQL statement. More...
 
 get_records_sql_menu ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 Get the first two columns from a number of records as an associative array using a SQL statement. More...
 
 get_recordset ($table, array $conditions=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get a number of records as a moodle_recordset where all the given conditions met. More...
 
 get_recordset_list ($table, $field, array $values, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get a number of records as a moodle_recordset where one field match one list of values. More...
 
 get_recordset_select ($table, $select, array $params=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Get a number of records as a moodle_recordset which match a particular WHERE clause. More...
 
 get_recordset_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 Get a number of records as a moodle_recordset using a SQL statement. More...
 
 get_row_format ($table=null)
 Get the row format from the database schema. More...
 
 get_row_format_sql ($engine=null, $collation=null)
 Determine if the row format should be set to compressed, dynamic, or default. More...
 
 get_server_info ()
 Returns database server info array. More...
 
 get_session_lock ($rowid, $timeout)
 Obtain session lock. More...
 
 get_tables ($usecache=true)
 Return tables in database WITHOUT current prefix. More...
 
 get_transaction_start_backtrace ()
 Returns transaction trace for debugging purposes. More...
 
 has_breaking_change_sqlmode ()
 Indicates whether SQL_MODE default value has changed in a not backward compatible way. More...
 
 import_record ($table, $dataobject)
 Import a record into a table, id field is required. More...
 
 insert_record ($table, $dataobject, $returnid=true, $bulk=false)
 Insert a record into a table and return the "id" field if required. More...
 
 insert_record_raw ($table, $params, $returnid=true, $bulk=false, $customsequence=false)
 Insert new record into database, as fast as possible, no safety checks, lobs not supported. More...
 
 insert_records ($table, $dataobjects)
 Insert multiple records into database as fast as possible. More...
 
 is_compressed_row_format_supported ($cached=true)
 Is this database compatible with compressed row format? This feature is necessary for support of large number of text columns in InnoDB/XtraDB database. More...
 
 is_file_per_table_enabled ()
 Check the database to see if innodb_file_per_table is on. More...
 
 is_fulltext_search_supported ()
 Does this mariadb instance support fulltext indexes? More...
 
 is_large_prefix_enabled ()
 Check the database to see if innodb_large_prefix is on. More...
 
 is_transaction_started ()
 Returns true if a transaction is in progress. More...
 
 perf_get_queries ()
 Returns the number of queries done by this database. More...
 
 perf_get_queries_time ()
 Time waiting for the database engine to finish running all queries. More...
 
 perf_get_reads ()
 Returns the number of reads done by this database. More...
 
 perf_get_writes ()
 Returns the number of writes done by this database. More...
 
 query_log ($error=false)
 This logs the last query based on 'logall', 'logslow' and 'logerrors' options configured via $CFG->dboptions . More...
 
 record_exists ($table, array $conditions)
 Test whether a record exists in a table where all the given conditions met. More...
 
 record_exists_select ($table, $select, array $params=null)
 Test whether any records exists in a table which match a particular WHERE clause. More...
 
 record_exists_sql ($sql, array $params=null)
 Test whether a SQL SELECT statement returns any records. More...
 
 release_session_lock ($rowid)
 Releases the session lock. More...
 
 replace_all_text ($table, database_column_info $column, $search, $replace)
 Replace given text in all rows of column. More...
 
 replace_all_text_supported ()
 Does this driver support tool_replace? More...
 
 reset_caches ($tablenames=null)
 Resets the internal column details cache. More...
 
 rollback_delegated_transaction (moodle_transaction $transaction, $e)
 Call when delegated transaction failed, this rolls back all delegated transactions up to the top most level. More...
 
 session_lock_supported ()
 Is session lock supported in this driver? More...
 
 set_debug ($state)
 Enable/disable very detailed debugging. More...
 
 set_field ($table, $newfield, $newvalue, array $conditions=null)
 Set a single field in every table record where all the given conditions met. More...
 
 set_field_select ($table, $newfield, $newvalue, $select, array $params=null)
 Set a single field in every table record which match a particular WHERE clause. More...
 
 set_logging ($state)
 Enable/disable detailed sql logging. More...
 
 setup_is_unicodedb ()
 Is this database compatible with utf8? More...
 
 sql_bitand ($int1, $int2)
 Returns the SQL text to be used in order to perform one bitwise AND operation between 2 integers. More...
 
 sql_bitnot ($int1)
 Returns the SQL text to be used in order to perform one bitwise NOT operation with 1 integer. More...
 
 sql_bitor ($int1, $int2)
 Returns the SQL text to be used in order to perform one bitwise OR operation between 2 integers. More...
 
 sql_bitxor ($int1, $int2)
 Returns the SQL text to be used in order to perform one bitwise XOR operation between 2 integers. More...
 
 sql_cast_2signed ($fieldname)
 Returns the SQL to be used in order to an UNSIGNED INTEGER column to SIGNED. More...
 
 sql_cast_char2int ($fieldname, $text=false)
 Returns the SQL to be used in order to CAST one CHAR column to INTEGER. More...
 
 sql_cast_char2real ($fieldname, $text=false)
 Returns the SQL to be used in order to CAST one CHAR column to REAL number. More...
 
 sql_ceil ($fieldname)
 Returns the cross db correct CEIL (ceiling) expression applied to fieldname. More...
 
 sql_compare_text ($fieldname, $numchars=32)
 Returns the SQL text to be used to compare one TEXT (clob) column with one varchar column, because some RDBMS doesn't support such direct comparisons. More...
 
 sql_concat ()
 Returns the proper SQL to do CONCAT between the elements passed Can take many parameters. More...
 
 sql_concat_join ($separator="' '", $elements=array())
 Returns the proper SQL to do CONCAT between the elements passed with a given separator. More...
 
 sql_empty ()
 This used to return empty string replacement character. More...
 
 sql_equal ($fieldname, $param, $casesensitive=true, $accentsensitive=true, $notequal=false)
 Returns an equal (=) or not equal (<>) part of a query. More...
 
 sql_fullname ($first='firstname', $last='lastname')
 Returns the proper SQL (for the dbms in use) to concatenate $firstname and $lastname. More...
 
 sql_intersect ($selects, $fields)
 Returns the SQL that allows to find intersection of two or more queries. More...
 
 sql_isempty ($tablename, $fieldname, $nullablefield, $textfield)
 Returns the proper SQL to know if one field is empty. More...
 
 sql_isnotempty ($tablename, $fieldname, $nullablefield, $textfield)
 Returns the proper SQL to know if one field is not empty. More...
 
 sql_length ($fieldname)
 Returns the SQL text to be used to calculate the length in characters of one expression. More...
 
 sql_like ($fieldname, $param, $casesensitive=true, $accentsensitive=true, $notlike=false, $escapechar='\\')
 Returns 'LIKE' part of a query. More...
 
 sql_like_escape ($text, $escapechar='\\')
 Escape sql LIKE special characters like '_' or ''. More...
 
 sql_modulo ($int1, $int2)
 Returns the SQL text to be used in order to perform module '' operation - remainder after division. More...
 
 sql_null_from_clause ()
 Returns the FROM clause required by some DBs in all SELECT statements. More...
 
 sql_order_by_text ($fieldname, $numchars=32)
 Returns the SQL text to be used to order by one TEXT (clob) column, because some RDBMS doesn't support direct ordering of such fields. More...
 
 sql_position ($needle, $haystack)
 Returns the SQL for returning searching one string for the location of another. More...
 
 sql_regex ($positivematch=true, $casesensitive=false)
 Return regex positive or negative match sql. More...
 
 sql_regex_supported ()
 Does this driver support regex syntax when searching.
 
 sql_substr ($expr, $start, $length=false)
 Returns the proper substr() SQL text used to extract substrings from DB NOTE: this was originally returning only function name. More...
 
 start_delegated_transaction ()
 On DBs that support it, switch to transaction mode and begin a transaction you'll need to ensure you call allow_commit() on the returned object or your changes will be lost. More...
 
 transactions_forbidden ()
 This is a test that throws an exception if transaction in progress. More...
 
 update_record ($table, $dataobject, $bulk=false)
 Update a record in a table. More...
 
 update_record_raw ($table, $params, $bulk=false)
 Update record in database, as fast as possible, no safety checks, lobs not supported. More...
 
 update_temp_table_stats ()
 Analyze the data in temporary tables to force statistics collection after bulk data loads. More...
 

Static Public Member Functions

static get_driver_instance ($type, $library, $external=false)
 Loads and returns a database instance with the specified type and library. More...
 

Protected Member Functions

 allowed_param_types ()
 Returns supported query parameter types. More...
 
 begin_transaction ()
 Driver specific start of real database transaction, this can not be used directly in code. More...
 
 commit_transaction ()
 Driver specific commit of real database transaction, this can not be used directly in code. More...
 
 create_recordset ($result)
 
 detect_objects ($value)
 Detects object parameters and throws exception if found. More...
 
 emulate_bound_params ($sql, array $params=null)
 Very ugly hack which emulates bound parameters in queries because prepared statements do not use query cache.
 
 fix_table_name ($tablename)
 Fixes any table names that clash with reserved words. More...
 
 fix_table_names ($sql)
 Converts short table name {tablename} to the real prefixed table name in given sql. More...
 
 get_dblibrary ()
 Returns general database library name Note: can be used before connect() More...
 
 get_dbtype ()
 Returns more specific database driver type Note: can be used before connect() More...
 
 get_metacache ()
 Handle the creation and caching of the databasemeta information for all databases. More...
 
 get_settings_hash ()
 Returns a hash for the settings used during connection. More...
 
 get_temp_tables_cache ()
 Handle the creation and caching of the temporary tables. More...
 
 has_breaking_change_quoted_defaults ()
 Indicates whether column information retrieved from information_schema.columns has default values quoted or not. More...
 
 insert_chunk ($table, array $chunk, array $columns)
 Insert records in chunks. More...
 
 is_antelope_file_format_no_more_supported ()
 Tests if the Antelope file format is still supported or it has been removed. More...
 
 normalise_limit_from_num ($limitfrom, $limitnum)
 Ensures that limit params are numeric and positive integers, to be passed to the database. More...
 
 normalise_value ($column, $value)
 Normalise values based in RDBMS dependencies (booleans, LOBs...) More...
 
 print_debug ($sql, array $params=null, $obj=null)
 Prints sql debug info. More...
 
 print_debug_time ()
 Prints the time a query took to run. More...
 
 query_end ($result)
 This should be called immediately after each db query. More...
 
 query_log_allow ()
 Restore old logging behavior.
 
 query_log_prevent ()
 Disable logging temporarily.
 
 query_start ($sql, array $params=null, $type, $extrainfo=null)
 This should be called before each db query. More...
 
 query_time ()
 Returns the time elapsed since the query started. More...
 
 rollback_transaction ()
 Driver specific abort of real database transaction, this can not be used directly in code. More...
 
 store_settings ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null)
 Store various database settings. More...
 
 transactions_supported ()
 It is time to require transactions everywhere. More...
 
 where_clause ($table, array $conditions=null)
 Returns the SQL WHERE conditions. More...
 
 where_clause_list ($field, array $values)
 Returns SQL WHERE conditions for the ..._list group of methods. More...
 

Protected Attributes

bool $compressedrowformatsupported = null
 is compressed row format supported cache
 
database_manager $database_manager
 db manager which allows db structure modifications.
 
string $dbhost
 db host name.
 
string $dbname
 db name.
 
array $dboptions
 Database or driver specific options, such as sockets or TCP/IP db connections.
 
string $dbpass
 db host password.
 
string $dbuser
 db host user.
 
int $debug = 0
 Debug level.
 
bool $disposed
 flag marking database instance as disposed
 
bool $external
 True means non-moodle external database used.
 
string $last_extrainfo
 Last extra info.
 
array $last_params
 Last query parameters.
 
string $last_sql
 Last used query sql.
 
float $last_time
 Last time in seconds with millisecond precision.
 
int $last_type
 Last query type.
 
cache_application $metacache
 for column info
 
cache_request $metacachetemp
 for column info on temp tables
 
mysqli $mysqli = null
 $mysqli
 
string $prefix
 Prefix added to table names.
 
float $queriestime = 0
 Time queries took to finish, seconds with microseconds.
 
int $reads = 0
 The database reads (performance counter).
 
boolean $skiplogging = false
 variable use to temporarily disable logging.
 
array $tables = null
 Cache of table info.
 
moodle_temptables $temptables
 temptables manager to provide cross-db support for temp tables.
 
bool $used_for_db_sessions = false
 True if the db is used for db sessions.
 
int $writes = 0
 The database writes (performance counter).
 

Detailed Description

Native MariaDB class representing moodle database interface.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ allowed_param_types()

mysqli_native_moodle_database::allowed_param_types ( )
protectedinherited

Returns supported query parameter types.

Return values
intbitmask of accepted SQL_PARAMS_*

Reimplemented from moodle_database.

◆ begin_transaction()

mysqli_native_moodle_database::begin_transaction ( )
protectedinherited

Driver specific start of real database transaction, this can not be used directly in code.

Return values
void

Reimplemented from moodle_database.

◆ change_database_structure()

mysqli_native_moodle_database::change_database_structure (   $sql,
  $tablenames = null 
)
inherited

Do NOT use in code, to be used by database_manager only!

Parameters
string | array$sqlquery
array | null$tablenamesan array of xmldb table names affected by this request.
Return values
booltrue
Exceptions
ddl_change_structure_exceptionA DDL specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ change_db_encoding()

moodle_database::change_db_encoding ( )
inherited

Attempts to change db encoding to UTF-8 encoding if possible.

Return values
boolTrue is successful.

◆ commit_delegated_transaction()

moodle_database::commit_delegated_transaction ( moodle_transaction  $transaction)
inherited

Indicates delegated transaction finished successfully.

The real database transaction is committed only if all delegated transactions committed.

Parameters
moodle_transaction$transactionThe transaction to commit
Return values
void
Exceptions
dml_transaction_exceptionCreates and throws transaction related exceptions.

◆ commit_transaction()

mysqli_native_moodle_database::commit_transaction ( )
protectedinherited

Driver specific commit of real database transaction, this can not be used directly in code.

Return values
void

Reimplemented from moodle_database.

◆ connect()

mysqli_native_moodle_database::connect (   $dbhost,
  $dbuser,
  $dbpass,
  $dbname,
  $prefix,
array  $dboptions = null 
)
inherited

Connect to db Must be called before other methods.

Parameters
string$dbhostThe database host.
string$dbuserThe database username.
string$dbpassThe database username's password.
string$dbnameThe name of the database being connected to.e
mixed$prefixstring means moodle db prefix, false used for external databases where prefix not used
array$dboptionsdriver specific options
Return values
boolsuccess

Reimplemented from moodle_database.

◆ convert_table_row_format()

mysqli_native_moodle_database::convert_table_row_format (   $tablename)
inherited

Converts a table to either 'Compressed' or 'Dynamic' row format.

Parameters
string$tablenameName of the table to convert to the new row format.

◆ count_records()

moodle_database::count_records (   $table,
array  $conditions = null 
)
inherited

Count the records in a table where all the given conditions met.

Parameters
string$tableThe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Return values
intThe count of records returned from the specified criteria.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ count_records_select()

moodle_database::count_records_select (   $table,
  $select,
array  $params = null,
  $countitem = "COUNT('x')" 
)
inherited

Count the records in a table which match a particular WHERE clause.

Parameters
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a WHERE clause in the SQL call.
array$paramsarray of sql parameters
string$countitemThe count string to be used in the SQL call. Default is COUNT('x').
Return values
intThe count of records returned from the specified criteria.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ count_records_sql()

moodle_database::count_records_sql (   $sql,
array  $params = null 
)
inherited

Get the result of a SQL SELECT COUNT(...) query.

Given a query that counts rows, return that count. (In fact, given any query, return the first field of the first record returned. However, this method should only be used for the intended purpose.) If an error occurs, 0 is returned.

Parameters
string$sqlThe SQL string you wish to be executed.
array$paramsarray of sql parameters
Return values
intthe count
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ create_database()

mysqli_native_moodle_database::create_database (   $dbhost,
  $dbuser,
  $dbpass,
  $dbname,
array  $dboptions = null 
)
inherited

Attempt to create the database.

Parameters
string$dbhost
string$dbuser
string$dbpass
string$dbname
Return values
boolsuccess
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ delete_records()

moodle_database::delete_records (   $table,
array  $conditions = null 
)
inherited

Delete the records from a table where all the given conditions met.

If conditions not specified, table is truncated.

Parameters
string$tablethe table to delete from.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Return values
booltrue.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ delete_records_list()

moodle_database::delete_records_list (   $table,
  $field,
array  $values 
)
inherited

Delete the records from a table where one field match one list of values.

Parameters
string$tablethe table to delete from.
string$fieldThe field to search
array$valuesarray of values
Return values
booltrue.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ delete_records_select()

mysqli_native_moodle_database::delete_records_select (   $table,
  $select,
array  $params = null 
)
inherited

Delete one or more records from a table which match a particular WHERE clause.

Parameters
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria).
array$paramsarray of sql parameters
Return values
booltrue
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ delete_records_subquery()

mysqli_native_moodle_database::delete_records_subquery ( string  $table,
string  $field,
string  $alias,
string  $subquery,
array  $params = [] 
)
inherited

Deletes records using a subquery, which is done with a strange DELETE...JOIN syntax in MySQL because it performs very badly with normal subqueries.

Parameters
string$tableTable to delete from
string$fieldField in table to match
string$aliasName of single column in subquery e.g. 'id'
string$subqueryQuery that will return values of the field to delete
array$paramsParameters for query
Exceptions
dml_exceptionIf there is any error

Reimplemented from moodle_database.

◆ detect_objects()

moodle_database::detect_objects (   $value)
protectedinherited

Detects object parameters and throws exception if found.

Parameters
mixed$value
Return values
void
Exceptions
coding_exceptionif object detected

◆ diagnose()

mysqli_native_moodle_database::diagnose ( )
inherited

Diagnose database and tables, this function is used to verify database and driver settings, db engine types, etc.

Return values
stringnull means everything ok, string means problem found.

Reimplemented from moodle_database.

◆ dispose()

mysqli_native_moodle_database::dispose ( )
inherited

Close database connection and release all resources and memory (especially circular memory references).

Do NOT use connect() again, create a new instance if needed.

Reimplemented from moodle_database.

◆ driver_installed()

mysqli_native_moodle_database::driver_installed ( )
inherited

Detects if all needed PHP stuff installed.

Note: can be used before connect()

Return values
mixedtrue if ok, string if something

Reimplemented from moodle_database.

◆ execute()

mysqli_native_moodle_database::execute (   $sql,
array  $params = null 
)
inherited

Execute general sql query.

Should be used only when no other method suitable. Do NOT use this to make changes in db structure, use database_manager methods instead!

Parameters
string$sqlquery
array$paramsquery parameters
Return values
booltrue
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ export_dbconfig()

moodle_database::export_dbconfig ( )
inherited

Returns the db related part of config.php.

Return values
stdClass

◆ export_table_recordset()

mysqli_native_moodle_database::export_table_recordset (   $table)
inherited

Get all records from a table.

This method works around potential memory problems and may improve performance, this method may block access to table until the recordset is closed.

Parameters
string$tableName of database table.
Return values
moodle_recordsetA moodle_recordset instance get_recordset.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ fix_sql_params()

moodle_database::fix_sql_params (   $sql,
array  $params = null 
)
inherited

Normalizes sql query parameters and verifies parameters.

Parameters
string$sqlThe query or part of it.
array$paramsThe query parameters.
Return values
array(sql, params, type of params)

◆ fix_table_name()

mysqli_native_moodle_database::fix_table_name (   $tablename)
protectedinherited

Fixes any table names that clash with reserved words.

Parameters
string$tablenameThe table name
Return values
stringThe fixed table name

Reimplemented from moodle_database.

◆ fix_table_names()

moodle_database::fix_table_names (   $sql)
protectedinherited

Converts short table name {tablename} to the real prefixed table name in given sql.

Parameters
string$sqlThe sql to be operated on.
Return values
stringThe sql with tablenames being prefixed with $CFG->prefix

Reimplemented in sqlsrv_native_moodle_database, and oci_native_moodle_database.

◆ force_transaction_rollback()

moodle_database::force_transaction_rollback ( )
inherited

Force rollback of all delegated transaction.

Does not throw any exceptions and does not log anything.

This method should be used only from default exception handlers and other core code.

Return values
void

◆ get_columns()

mysqli_native_moodle_database::get_columns (   $table,
  $usecache = true 
)
inherited

Returns detailed information about columns in table.

This information is cached internally.

Parameters
string$tablename
bool$usecache
Return values
database_column_info[]array of database_column_info objects indexed with column names

Reimplemented from moodle_database.

◆ get_configuration_help()

mariadb_native_moodle_database::get_configuration_help ( )

Returns localised database configuration help.

Note: can be used before connect()

Return values
string

Reimplemented from mysqli_native_moodle_database.

◆ get_configuration_hints()

moodle_database::get_configuration_hints ( )
inherited

Returns the localised database description Note: can be used before connect()

Deprecated:
since 2.6
Return values
string

◆ get_dbcollation()

mysqli_native_moodle_database::get_dbcollation ( )
inherited

Returns the current MySQL db collation.

This is an ugly workaround for MySQL default collation problems.

Return values
stringor null MySQL collation name

◆ get_dbengine()

mysqli_native_moodle_database::get_dbengine ( )
inherited

Returns the current MySQL db engine.

This is an ugly workaround for MySQL default engine problems, Moodle is designed to work best on ACID compliant databases with full transaction support. Do not use MyISAM.

Return values
stringor null MySQL engine name

◆ get_dbfamily()

mysqli_native_moodle_database::get_dbfamily ( )
inherited

Returns database family type - describes SQL dialect Note: can be used before connect()

Return values
stringdb family name (mysql, postgres, mssql, oracle, etc.)

Reimplemented from moodle_database.

◆ get_dblibrary()

mysqli_native_moodle_database::get_dblibrary ( )
protectedinherited

Returns general database library name Note: can be used before connect()

Return values
stringdb type pdo, native

Reimplemented from moodle_database.

◆ get_dbtype()

mariadb_native_moodle_database::get_dbtype ( )
protected

Returns more specific database driver type Note: can be used before connect()

Return values
stringdb type mysqli, pgsql, oci, mssql, sqlsrv

Reimplemented from mysqli_native_moodle_database.

◆ get_dbvendor()

mariadb_native_moodle_database::get_dbvendor ( )

Returns the database vendor.

Note: can be used before connect()

Return values
stringThe db vendor name, usually the same as db family name.

Reimplemented from moodle_database.

◆ get_debug()

moodle_database::get_debug ( )
inherited

Returns debug status.

Return values
bool::$state

◆ get_driver_instance()

static moodle_database::get_driver_instance (   $type,
  $library,
  $external = false 
)
staticinherited

Loads and returns a database instance with the specified type and library.

The loaded class is within lib/dml directory and of the form: $type.'_'.$library.'_moodle_database'

Parameters
string$typeDatabase driver's type. (eg: mysqli, pgsql, mssql, sqldrv, oci, etc.)
string$libraryDatabase driver's library (native, pdo, etc.)
bool$externalTrue if this is an external database.
Return values
moodle_databasedriver object or null if error, for example of driver object see mysqli_native_moodle_database

◆ get_field()

moodle_database::get_field (   $table,
  $return,
array  $conditions,
  $strictness = IGNORE_MISSING 
)
inherited

Get a single field value from a table record where all the given conditions met.

Parameters
string$tablethe table to query.
string$returnthe field to return the value of.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Return values
mixedthe specified value false if not found
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_field_select()

moodle_database::get_field_select (   $table,
  $return,
  $select,
array  $params = null,
  $strictness = IGNORE_MISSING 
)
inherited

Get a single field value from a table record which match a particular WHERE clause.

Parameters
string$tablethe table to query.
string$returnthe field to return the value of.
string$selectA fragment of SQL to be used in a where clause returning one row with one column
array$paramsarray of sql parameters
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Return values
mixedthe specified value false if not found
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_field_sql()

moodle_database::get_field_sql (   $sql,
array  $params = null,
  $strictness = IGNORE_MISSING 
)
inherited

Get a single field value (first field) using a SQL statement.

Parameters
string$sqlThe SQL query returning one row with one column
array$paramsarray of sql parameters
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Return values
mixedthe specified value false if not found
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_fieldset_select()

moodle_database::get_fieldset_select (   $table,
  $return,
  $select,
array  $params = null 
)
inherited

Selects records and return values of chosen field as an array which match a particular WHERE clause.

Parameters
string$tablethe table to query.
string$returnthe field we are intered in
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
Return values
arrayof values
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_fieldset_sql()

mysqli_native_moodle_database::get_fieldset_sql (   $sql,
array  $params = null 
)
inherited

Selects records and return values (first field) as an array using a SQL statement.

Parameters
string$sqlThe SQL query
array$paramsarray of sql parameters
Return values
arrayof values
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ get_in_or_equal()

moodle_database::get_in_or_equal (   $items,
  $type = SQL_PARAMS_QM,
  $prefix = 'param',
  $equal = true,
  $onemptyitems = false 
)
inherited

Constructs 'IN()' or '=' sql fragment.

Parameters
mixed$itemsA single value or array of values for the expression.
int$typeParameter bounding type : SQL_PARAMS_QM or SQL_PARAMS_NAMED.
string$prefixNamed parameter placeholder prefix (a unique counter value is appended to each parameter name).
bool$equalTrue means we want to equate to the constructed expression, false means we don't want to equate to it.
mixed$onemptyitemsThis defines the behavior when the array of items provided is empty. Defaults to false, meaning throw exceptions. Other values will become part of the returned SQL fragment.
Exceptions
coding_exception| dml_exception
Return values
arrayA list containing the constructed sql fragment and an array of parameters.

Reimplemented in oci_native_moodle_database.

◆ get_indexes()

mysqli_native_moodle_database::get_indexes (   $table)
inherited

Return table indexes - everything lowercased.

Parameters
string$tableThe table we want to get indexes from.
Return values
arrayAn associative array of indexes containing 'unique' flag and 'columns' being indexed

Reimplemented from moodle_database.

◆ get_last_error()

mysqli_native_moodle_database::get_last_error ( )
inherited

Returns last error reported by database engine.

Return values
stringerror message

Reimplemented from moodle_database.

◆ get_manager()

moodle_database::get_manager ( )
inherited

Returns the sql generator used for db manipulation.

Used mostly in upgrade.php scripts.

Return values
database_managerThe instance used to perform ddl operations.
See also
lib/ddl/database_manager.php

◆ get_metacache()

moodle_database::get_metacache ( )
protectedinherited

Handle the creation and caching of the databasemeta information for all databases.

Return values
cache_applicationThe databasemeta cachestore to complete operations on.

◆ get_name()

mariadb_native_moodle_database::get_name ( )

Returns localised database type name Note: can be used before connect()

Return values
string

Reimplemented from mysqli_native_moodle_database.

◆ get_prefix()

moodle_database::get_prefix ( )
inherited

Returns database table prefix Note: can be used before connect()

Return values
stringThe prefix used in the database.

◆ get_record()

moodle_database::get_record (   $table,
array  $conditions,
  $fields = '*',
  $strictness = IGNORE_MISSING 
)
inherited

Get a single database record as an object where all the given conditions met.

Parameters
string$tableThe table to select from.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$fieldsA comma separated list of fields to be returned from the chosen table.
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means we will throw an exception if no record or multiple records found.
Todo:
MDL-30407 MUST_EXIST option should not throw a dml_exception, it should throw a different exception as it's a requested check.
Return values
mixeda fieldset object containing the first matching record, false or exception if error not found depending on mode
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_record_select()

moodle_database::get_record_select (   $table,
  $select,
array  $params = null,
  $fields = '*',
  $strictness = IGNORE_MISSING 
)
inherited

Get a single database record as an object which match a particular WHERE clause.

Parameters
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
string$fieldsA comma separated list of fields to be returned from the chosen table.
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Return values
stdClass|falsea fieldset object containing the first matching record, false or exception if error not found depending on mode
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_record_sql()

moodle_database::get_record_sql (   $sql,
array  $params = null,
  $strictness = IGNORE_MISSING 
)
inherited

Get a single database record as an object using a SQL statement.

The SQL statement should normally only return one record. It is recommended to use get_records_sql() if more matches possible!

Parameters
string$sqlThe SQL string you wish to be executed, should normally only return one record.
array$paramsarray of sql parameters
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Return values
mixeda fieldset object containing the first matching record, false or exception if error not found depending on mode
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented in oci_native_moodle_database.

◆ get_records()

moodle_database::get_records (   $table,
array  $conditions = null,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as an array of objects where all the given conditions met.

If the query succeeds and returns at least one record, the return value is an array of objects, one object for each record found. The array key is the value from the first column of the result set. The object associated with that key has a member variable for each column of the results.

Parameters
string$tablethe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned). The first field will be used as key for the array so must be a unique field such as 'id'.
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records in total (optional, required if $limitfrom is set).
Return values
arrayAn array of Objects indexed by first column.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_records_list()

moodle_database::get_records_list (   $table,
  $field,
array  $values,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as an array of objects where one field match one list of values.

Return value is like get_records.

Parameters
string$tableThe database table to be checked against.
string$fieldThe field to search
array$valuesAn array of values
string$sortSort order (as valid SQL sort parameter)
string$fieldsA comma separated list of fields to be returned from the chosen table. If specified, the first field should be a unique one such as 'id' since it will be used as a key in the associative array.
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records in total (optional).
Return values
arrayAn array of objects indexed by first column
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_records_menu()

moodle_database::get_records_menu (   $table,
array  $conditions = null,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get the first two columns from a number of records as an associative array where all the given conditions met.

Arguments are like get_recordset.

If no errors occur the return value is an associative whose keys come from the first field of each record, and whose values are the corresponding second fields. False is returned if an error occurs.

Parameters
string$tablethe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return - the number of fields should be 2!
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
arrayan associative array
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_records_select()

moodle_database::get_records_select (   $table,
  $select,
array  $params = null,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as an array of objects which match a particular WHERE clause.

Return value is like get_records.

Parameters
string$tableThe table to query.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsAn array of sql parameters
string$sortAn order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsA comma separated list of fields to return (optional, by default all fields are returned). The first field will be used as key for the array so must be a unique field such as 'id'.
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records in total (optional, required if $limitfrom is set).
Return values
arrayof objects indexed by first column
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_records_select_menu()

moodle_database::get_records_select_menu (   $table,
  $select,
array  $params = null,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get the first two columns from a number of records as an associative array which match a particular WHERE clause.

Arguments are like get_recordset_select}. * Return value is like function get_records_menu.

Parameters
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
string$sortSort order (optional) - a valid SQL order parameter
string$fieldsA comma separated list of fields to be returned from the chosen table - the number of fields should be 2!
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
arrayan associative array
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_records_sql()

mysqli_native_moodle_database::get_records_sql (   $sql,
array  $params = null,
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as an array of objects using a SQL statement.

Return value is like:

See also
function get_records.
Parameters
string$sqlthe SQL select query to execute. The first column of this SELECT statement must be a unique value (usually the 'id' field), as it will be used as the key of the returned array.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
arrayof objects, or empty array if no records were found
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ get_records_sql_menu()

moodle_database::get_records_sql_menu (   $sql,
array  $params = null,
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get the first two columns from a number of records as an associative array using a SQL statement.

Arguments are like get_recordset_sql}. * Return value is like function get_records_menu.

Parameters
string$sqlThe SQL string you wish to be executed.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
arrayan associative array
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_recordset()

moodle_database::get_recordset (   $table,
array  $conditions = null,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as a moodle_recordset where all the given conditions met.

Selects records from the table $table.

If specified, only records meeting $conditions.

If specified, the results will be sorted as specified by $sort. This is added to the SQL as "ORDER BY $sort". Example values of $sort might be "time ASC" or "time DESC".

If $fields is specified, only those fields are returned.

Since this method is a little less readable, use of it should be restricted to code where it's possible there might be large datasets being returned. For known small datasets use get_records - it leads to simpler code.

If you only want some of the records, specify $limitfrom and $limitnum. The query will skip the first $limitfrom records (according to the sort order) and then return the next $limitnum records. If either of $limitfrom or $limitnum is specified, both must be present.

The return value is a moodle_recordset if the query succeeds. If an error occurs, false is returned.

Parameters
string$tablethe table to query.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned).
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
moodle_recordsetA moodle_recordset instance
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_recordset_list()

moodle_database::get_recordset_list (   $table,
  $field,
array  $values,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as a moodle_recordset where one field match one list of values.

Only records where $field takes one of the values $values are returned. $values must be an array of values.

Other arguments and the return type are like get_recordset.

Parameters
string$tablethe table to query.
string$fielda field to check (optional).
array$valuesarray of values the field must have
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned).
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
moodle_recordsetA moodle_recordset instance.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_recordset_select()

moodle_database::get_recordset_select (   $table,
  $select,
array  $params = null,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as a moodle_recordset which match a particular WHERE clause.

If given, $select is used as the SELECT parameter in the SQL query, otherwise all records from the table are returned.

Other arguments and the return type are like get_recordset.

Parameters
string$tablethe table to query.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return (optional, by default all fields are returned).
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
moodle_recordsetA moodle_recordset instance.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ get_recordset_sql()

mysqli_native_moodle_database::get_recordset_sql (   $sql,
array  $params = null,
  $limitfrom = 0,
  $limitnum = 0 
)
inherited

Get a number of records as a moodle_recordset using a SQL statement.

Since this method is a little less readable, use of it should be restricted to code where it's possible there might be large datasets being returned. For known small datasets use get_records_sql - it leads to simpler code.

The return type is like:

See also
function get_recordset.
Parameters
string$sqlthe SQL select query to execute.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Return values
moodle_recordsetinstance
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ get_row_format()

mysqli_native_moodle_database::get_row_format (   $table = null)
inherited

Get the row format from the database schema.

Parameters
string$table
Return values
stringrow_format name or null if not known or table does not exist.

◆ get_row_format_sql()

mysqli_native_moodle_database::get_row_format_sql (   $engine = null,
  $collation = null 
)
inherited

Determine if the row format should be set to compressed, dynamic, or default.

Terrible kludge. If we're using utf8mb4 AND we're using InnoDB, we need to specify row format to be either dynamic or compressed (default is compact) in order to allow for bigger indexes (MySQL errors #1709 and #1071).

Parameters
string$engineThe database engine being used. Will be looked up if not supplied.
string$collationThe database collation to use. Will look up the current collation if not supplied.
Return values
stringAn sql fragment to add to sql statements.

◆ get_server_info()

mariadb_native_moodle_database::get_server_info ( )

Returns database server info array.

Return values
arrayArray containing 'description' and 'version' info

Reimplemented from mysqli_native_moodle_database.

◆ get_session_lock()

mysqli_native_moodle_database::get_session_lock (   $rowid,
  $timeout 
)
inherited

Obtain session lock.

Parameters
int$rowidid of the row with session record
int$timeoutmax allowed time to wait for the lock in seconds
Return values
void

Reimplemented from moodle_database.

◆ get_settings_hash()

moodle_database::get_settings_hash ( )
protectedinherited

Returns a hash for the settings used during connection.

If not already requested it is generated and stored in a private property.

Return values
string

◆ get_tables()

mysqli_native_moodle_database::get_tables (   $usecache = true)
inherited

Return tables in database WITHOUT current prefix.

Parameters
bool$usecacheif true, returns list of cached tables.
Return values
arrayof table names in lowercase and without prefix

Reimplemented from moodle_database.

◆ get_temp_tables_cache()

moodle_database::get_temp_tables_cache ( )
protectedinherited

Handle the creation and caching of the temporary tables.

Return values
cache_applicationThe temp_tables cachestore to complete operations on.

◆ get_transaction_start_backtrace()

moodle_database::get_transaction_start_backtrace ( )
inherited

Returns transaction trace for debugging purposes.

to be used by core only

Return values
arrayor null if not in transaction.

◆ has_breaking_change_quoted_defaults()

mariadb_native_moodle_database::has_breaking_change_quoted_defaults ( )
protected

Indicates whether column information retrieved from information_schema.columns has default values quoted or not.

Return values
booleanTrue when default values are quoted (breaking change); otherwise, false.

Reimplemented from mysqli_native_moodle_database.

◆ has_breaking_change_sqlmode()

mariadb_native_moodle_database::has_breaking_change_sqlmode ( )

Indicates whether SQL_MODE default value has changed in a not backward compatible way.

Return values
booleanTrue when SQL_MODE breaks BC; otherwise, false.

Reimplemented from mysqli_native_moodle_database.

◆ import_record()

mysqli_native_moodle_database::import_record (   $table,
  $dataobject 
)
inherited

Import a record into a table, id field is required.

Safety checks are NOT carried out. Lobs are supported.

Parameters
string$tablename of database table to be inserted into
object$dataobjectA data object with values for one or more fields in the record
Return values
booltrue
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ insert_chunk()

mysqli_native_moodle_database::insert_chunk (   $table,
array  $chunk,
array  $columns 
)
protectedinherited

Insert records in chunks.

Note: can be used only from insert_records().

Parameters
string$table
array$chunk
database_column_info[]$columns

◆ insert_record()

mysqli_native_moodle_database::insert_record (   $table,
  $dataobject,
  $returnid = true,
  $bulk = false 
)
inherited

Insert a record into a table and return the "id" field if required.

Some conversions and safety checks are carried out. Lobs are supported. If the return ID isn't required, then this just reports success as true/false. $data is an object containing needed data

Parameters
string$tableThe database table to be inserted into
object$dataA data object with values for one or more fields in the record
bool$returnidShould the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
Return values
bool|inttrue or new id
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ insert_record_raw()

mysqli_native_moodle_database::insert_record_raw (   $table,
  $params,
  $returnid = true,
  $bulk = false,
  $customsequence = false 
)
inherited

Insert new record into database, as fast as possible, no safety checks, lobs not supported.

Parameters
string$tablename
mixed$paramsdata record as object or array
bool$returnitreturn it of inserted record
bool$bulktrue means repeated inserts expected
bool$customsequencetrue if 'id' included in $params, disables $returnid
Return values
bool|inttrue or new id
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ insert_records()

mysqli_native_moodle_database::insert_records (   $table,
  $dataobjects 
)
inherited

Insert multiple records into database as fast as possible.

Order of inserts is maintained, but the operation is not atomic, use transactions if necessary.

This method is intended for inserting of large number of small objects, do not use for huge objects with text or binary fields.

Since
Moodle 2.7
Parameters
string$tableThe database table to be inserted into
array | Traversable$dataobjectslist of objects to be inserted, must be compatible with foreach
Return values
voiddoes not return new record ids
Exceptions
coding_exceptionif data objects have different structure
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ is_antelope_file_format_no_more_supported()

mysqli_native_moodle_database::is_antelope_file_format_no_more_supported ( )
protectedinherited

Tests if the Antelope file format is still supported or it has been removed.

When removed, only Barracuda file format is supported, given the XtraDB/InnoDB engine.

Return values
boolTrue if the Antelope file format has been removed; otherwise, false.

◆ is_compressed_row_format_supported()

mysqli_native_moodle_database::is_compressed_row_format_supported (   $cached = true)
inherited

Is this database compatible with compressed row format? This feature is necessary for support of large number of text columns in InnoDB/XtraDB database.

Parameters
bool$cacheduse cached result
Return values
booltrue if table can be created or changed to compressed row format.

◆ is_file_per_table_enabled()

mysqli_native_moodle_database::is_file_per_table_enabled ( )
inherited

Check the database to see if innodb_file_per_table is on.

Return values
boolTrue if on otherwise false.

◆ is_fulltext_search_supported()

mariadb_native_moodle_database::is_fulltext_search_supported ( )

Does this mariadb instance support fulltext indexes?

Return values
bool

Reimplemented from mysqli_native_moodle_database.

◆ is_large_prefix_enabled()

mysqli_native_moodle_database::is_large_prefix_enabled ( )
inherited

Check the database to see if innodb_large_prefix is on.

Return values
boolTrue if on otherwise false.

◆ is_transaction_started()

moodle_database::is_transaction_started ( )
inherited

Returns true if a transaction is in progress.

Return values
bool

◆ normalise_limit_from_num()

moodle_database::normalise_limit_from_num (   $limitfrom,
  $limitnum 
)
protectedinherited

Ensures that limit params are numeric and positive integers, to be passed to the database.

We explicitly treat null, '' and -1 as 0 in order to provide compatibility with how limit values have been passed historically.

Parameters
int$limitfromWhere to start results from
int$limitnumHow many results to return
Return values
arrayNormalised limit params in array($limitfrom, $limitnum)

◆ normalise_value()

mysqli_native_moodle_database::normalise_value (   $column,
  $value 
)
protectedinherited

Normalise values based in RDBMS dependencies (booleans, LOBs...)

Parameters
database_column_info$columncolumn metadata corresponding with the value we are going to normalise
mixed$valuevalue we are going to normalise
Return values
mixedthe normalised value

Reimplemented from moodle_database.

◆ perf_get_queries()

moodle_database::perf_get_queries ( )
inherited

Returns the number of queries done by this database.

Return values
intNumber of queries.

◆ perf_get_queries_time()

moodle_database::perf_get_queries_time ( )
inherited

Time waiting for the database engine to finish running all queries.

Return values
floatNumber of seconds with microseconds

◆ perf_get_reads()

moodle_database::perf_get_reads ( )
inherited

Returns the number of reads done by this database.

Return values
intNumber of reads.

◆ perf_get_writes()

moodle_database::perf_get_writes ( )
inherited

Returns the number of writes done by this database.

Return values
intNumber of writes.

◆ print_debug()

moodle_database::print_debug (   $sql,
array  $params = null,
  $obj = null 
)
protectedinherited

Prints sql debug info.

Parameters
string$sqlThe query which is being debugged.
array$paramsThe query parameters. (optional)
mixed$objThe library specific object. (optional)
Return values
void

◆ print_debug_time()

moodle_database::print_debug_time ( )
protectedinherited

Prints the time a query took to run.

Return values
void

◆ query_end()

moodle_database::query_end (   $result)
protectedinherited

This should be called immediately after each db query.

It does a clean up of resources. It also throws exceptions if the sql that ran produced errors.

Parameters
mixed$resultThe db specific result obtained from running a query.
Exceptions
dml_read_exception| dml_write_exception | ddl_change_structure_exception
Return values
void

Reimplemented in sqlsrv_native_moodle_database, and pgsql_native_moodle_database.

◆ query_log()

moodle_database::query_log (   $error = false)
inherited

This logs the last query based on 'logall', 'logslow' and 'logerrors' options configured via $CFG->dboptions .

Parameters
string | bool$erroror false if not error
Return values
void

◆ query_start()

moodle_database::query_start (   $sql,
array  $params = null,
  $type,
  $extrainfo = null 
)
protectedinherited

This should be called before each db query.

Parameters
string$sqlThe query string.
array$paramsAn array of parameters.
int$typeThe type of query. ( SQL_QUERY_SELECT | SQL_QUERY_AUX | SQL_QUERY_INSERT | SQL_QUERY_UPDATE | SQL_QUERY_STRUCTURE )
mixed$extrainfoThis is here for any driver specific extra information.
Return values
void

Reimplemented in sqlsrv_native_moodle_database, pgsql_native_moodle_database, pdo_moodle_database, and oci_native_moodle_database.

◆ query_time()

moodle_database::query_time ( )
protectedinherited

Returns the time elapsed since the query started.

Return values
floatSeconds with microseconds

◆ record_exists()

moodle_database::record_exists (   $table,
array  $conditions 
)
inherited

Test whether a record exists in a table where all the given conditions met.

Parameters
string$tableThe table to check.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Return values
booltrue if a matching record exists, else false.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ record_exists_select()

moodle_database::record_exists_select (   $table,
  $select,
array  $params = null 
)
inherited

Test whether any records exists in a table which match a particular WHERE clause.

Parameters
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a WHERE clause in the SQL call.
array$paramsarray of sql parameters
Return values
booltrue if a matching record exists, else false.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ record_exists_sql()

moodle_database::record_exists_sql (   $sql,
array  $params = null 
)
inherited

Test whether a SQL SELECT statement returns any records.

This function returns true if the SQL statement executes without any errors and returns at least one record.

Parameters
string$sqlThe SQL statement to execute.
array$paramsarray of sql parameters
Return values
booltrue if the SQL executes without errors and returns at least one record.
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ release_session_lock()

mysqli_native_moodle_database::release_session_lock (   $rowid)
inherited

Releases the session lock.

Parameters
int$rowidThe id of the row with session record.
Return values
void
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ replace_all_text()

moodle_database::replace_all_text (   $table,
database_column_info  $column,
  $search,
  $replace 
)
inherited

Replace given text in all rows of column.

Since
Moodle 2.6.1
Parameters
string$tablename of the table
database_column_info$column
string$search
string$replace

◆ replace_all_text_supported()

mysqli_native_moodle_database::replace_all_text_supported ( )
inherited

Does this driver support tool_replace?

Since
Moodle 2.6.1
Return values
bool

Reimplemented from moodle_database.

◆ reset_caches()

moodle_database::reset_caches (   $tablenames = null)
inherited

Resets the internal column details cache.

Parameters
array | null$tablenamesan array of xmldb table names affected by this request.
Return values
void

◆ rollback_delegated_transaction()

moodle_database::rollback_delegated_transaction ( moodle_transaction  $transaction,
  $e 
)
inherited

Call when delegated transaction failed, this rolls back all delegated transactions up to the top most level.

In many cases you do not need to call this method manually, because all open delegated transactions are rolled back automatically if exceptions not caught.

Parameters
moodle_transaction$transactionAn instance of a moodle_transaction.
Exception | Throwable$eThe related exception/throwable to this transaction rollback.
Return values
voidThis does not return, instead the exception passed in will be rethrown.

◆ rollback_transaction()

mysqli_native_moodle_database::rollback_transaction ( )
protectedinherited

Driver specific abort of real database transaction, this can not be used directly in code.

Return values
void

Reimplemented from moodle_database.

◆ session_lock_supported()

mysqli_native_moodle_database::session_lock_supported ( )
inherited

Is session lock supported in this driver?

Return values
bool

Reimplemented from moodle_database.

◆ set_debug()

moodle_database::set_debug (   $state)
inherited

Enable/disable very detailed debugging.

Parameters
bool$state
Return values
void

◆ set_field()

moodle_database::set_field (   $table,
  $newfield,
  $newvalue,
array  $conditions = null 
)
inherited

Set a single field in every table record where all the given conditions met.

Parameters
string$tableThe database table to be checked against.
string$newfieldthe field to set.
string$newvaluethe value to set the field to.
array$conditionsoptional array $fieldname=>requestedvalue with AND in between
Return values
booltrue
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

◆ set_field_select()

mysqli_native_moodle_database::set_field_select (   $table,
  $newfield,
  $newvalue,
  $select,
array  $params = null 
)
inherited

Set a single field in every table record which match a particular WHERE clause.

Parameters
string$tableThe database table to be checked against.
string$newfieldthe field to set.
string$newvaluethe value to set the field to.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
Return values
booltrue
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ set_logging()

moodle_database::set_logging (   $state)
inherited

Enable/disable detailed sql logging.

Deprecated:
since Moodle 2.9

◆ setup_is_unicodedb()

mysqli_native_moodle_database::setup_is_unicodedb ( )
inherited

Is this database compatible with utf8?

Return values
bool

Reimplemented from moodle_database.

◆ sql_bitand()

moodle_database::sql_bitand (   $int1,
  $int2 
)
inherited

Returns the SQL text to be used in order to perform one bitwise AND operation between 2 integers.

NOTE: The SQL result is a number and can not be used directly in SQL condition, please compare it to some number to get a bool!!

Parameters
int$int1First integer in the operation.
int$int2Second integer in the operation.
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database.

◆ sql_bitnot()

moodle_database::sql_bitnot (   $int1)
inherited

Returns the SQL text to be used in order to perform one bitwise NOT operation with 1 integer.

Parameters
int$int1The operand integer in the operation.
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database.

◆ sql_bitor()

moodle_database::sql_bitor (   $int1,
  $int2 
)
inherited

Returns the SQL text to be used in order to perform one bitwise OR operation between 2 integers.

NOTE: The SQL result is a number and can not be used directly in SQL condition, please compare it to some number to get a bool!!

Parameters
int$int1The first operand integer in the operation.
int$int2The second operand integer in the operation.
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database.

◆ sql_bitxor()

moodle_database::sql_bitxor (   $int1,
  $int2 
)
inherited

Returns the SQL text to be used in order to perform one bitwise XOR operation between 2 integers.

NOTE: The SQL result is a number and can not be used directly in SQL condition, please compare it to some number to get a bool!!

Parameters
int$int1The first operand integer in the operation.
int$int2The second operand integer in the operation.
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented in pgsql_native_moodle_database, and oci_native_moodle_database.

◆ sql_cast_2signed()

mysqli_native_moodle_database::sql_cast_2signed (   $fieldname)
inherited

Returns the SQL to be used in order to an UNSIGNED INTEGER column to SIGNED.

Deprecated:
since 2.3
Parameters
string$fieldnameThe name of the field to be cast
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented from moodle_database.

◆ sql_cast_char2int()

mysqli_native_moodle_database::sql_cast_char2int (   $fieldname,
  $text = false 
)
inherited

Returns the SQL to be used in order to CAST one CHAR column to INTEGER.

Be aware that the CHAR column you're trying to cast contains really int values or the RDBMS will throw an error!

Parameters
string$fieldnameThe name of the field to be casted.
bool$textSpecifies if the original column is one TEXT (CLOB) column (true). Defaults to false.
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented from moodle_database.

◆ sql_cast_char2real()

mysqli_native_moodle_database::sql_cast_char2real (   $fieldname,
  $text = false 
)
inherited

Returns the SQL to be used in order to CAST one CHAR column to REAL number.

Be aware that the CHAR column you're trying to cast contains really numbers or the RDBMS will throw an error!

Parameters
string$fieldnameThe name of the field to be casted.
bool$textSpecifies if the original column is one TEXT (CLOB) column (true). Defaults to false.
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented from moodle_database.

◆ sql_ceil()

moodle_database::sql_ceil (   $fieldname)
inherited

Returns the cross db correct CEIL (ceiling) expression applied to fieldname.

note: Most DBs use CEIL(), hence it's the default here.

Parameters
string$fieldnameThe field (or expression) we are going to ceil.
Return values
stringThe piece of SQL code to be used in your ceiling statement.

Reimplemented in sqlsrv_native_moodle_database.

◆ sql_compare_text()

moodle_database::sql_compare_text (   $fieldname,
  $numchars = 32 
)
inherited

Returns the SQL text to be used to compare one TEXT (clob) column with one varchar column, because some RDBMS doesn't support such direct comparisons.

Parameters
string$fieldnameThe name of the TEXT field we need to order by
int$numcharsNumber of chars to use for the ordering (defaults to 32).
Return values
stringThe piece of SQL code to be used in your statement.

◆ sql_concat()

mysqli_native_moodle_database::sql_concat ( )
inherited

Returns the proper SQL to do CONCAT between the elements passed Can take many parameters.

Parameters
string$str,...1 or more fields/strings to concat
Return values
stringThe concat sql

Reimplemented from moodle_database.

◆ sql_concat_join()

mysqli_native_moodle_database::sql_concat_join (   $separator = "' '",
  $elements = array() 
)
inherited

Returns the proper SQL to do CONCAT between the elements passed with a given separator.

Parameters
string$separatorThe string to use as the separator
array$elementsAn array of items to concatenate
Return values
stringThe concat SQL

Reimplemented from moodle_database.

◆ sql_empty()

moodle_database::sql_empty ( )
inherited

This used to return empty string replacement character.

Deprecated:
use bound parameter with empty string instead
Return values
stringAn empty string.

◆ sql_equal()

mysqli_native_moodle_database::sql_equal (   $fieldname,
  $param,
  $casesensitive = true,
  $accentsensitive = true,
  $notequal = false 
)
inherited

Returns an equal (=) or not equal (<>) part of a query.

Note the use of this method may lead to slower queries (full scans) so use it only when needed and against already reduced data sets.

Since
Moodle 3.2
Parameters
string$fieldnameUsually the name of the table column.
string$paramUsually the bound query parameter (?, :named).
bool$casesensitiveUse case sensitive search when set to true (default).
bool$accentsensitiveUse accent sensitive search when set to true (default). (not all databases support accent insensitive)
bool$notequalTrue means not equal (<>)
Return values
stringThe SQL code fragment.

Reimplemented from moodle_database.

◆ sql_fullname()

moodle_database::sql_fullname (   $first = 'firstname',
  $last = 'lastname' 
)
inherited

Returns the proper SQL (for the dbms in use) to concatenate $firstname and $lastname.

Todo:
MDL-31233 This may not be needed here.
Parameters
string$firstUser's first name (default:'firstname').
string$lastUser's last name (default:'lastname').
Return values
stringThe SQL to concatenate strings.

◆ sql_intersect()

mysqli_native_moodle_database::sql_intersect (   $selects,
  $fields 
)
inherited

Returns the SQL that allows to find intersection of two or more queries.

Since
Moodle 2.8
Parameters
array$selectsarray of SQL select queries, each of them only returns fields with the names from $fields
string$fieldscomma-separated list of fields
Return values
stringSQL query that will return only values that are present in each of selects

Reimplemented from moodle_database.

◆ sql_isempty()

moodle_database::sql_isempty (   $tablename,
  $fieldname,
  $nullablefield,
  $textfield 
)
inherited

Returns the proper SQL to know if one field is empty.

Note that the function behavior strongly relies on the parameters passed describing the field so, please, be accurate when specifying them.

Also, note that this function is not suitable to look for fields having NULL contents at all. It's all for empty values!

This function should be applied in all the places where conditions of the type:

... AND fieldname = '';

are being used. Final result for text fields should be:

... AND ' . sql_isempty('tablename', 'fieldname', true/false, true);

and for varchar fields result should be:

... AND fieldname = :empty; "; $params['empty'] = '';

(see parameters description below)

Parameters
string$tablenameName of the table (without prefix). Not used for now but can be necessary in the future if we want to use some introspection using meta information against the DB. /// TODO ///
string$fieldnameName of the field we are going to check
bool$nullablefieldFor specifying if the field is nullable (true) or no (false) in the DB.
bool$textfieldFor specifying if it is a text (also called clob) field (true) or a varchar one (false)
Return values
stringthe sql code to be added to check for empty values

Reimplemented in sqlsrv_native_moodle_database, and oci_native_moodle_database.

◆ sql_isnotempty()

moodle_database::sql_isnotempty (   $tablename,
  $fieldname,
  $nullablefield,
  $textfield 
)
inherited

Returns the proper SQL to know if one field is not empty.

Note that the function behavior strongly relies on the parameters passed describing the field so, please, be accurate when specifying them.

This function should be applied in all the places where conditions of the type:

... AND fieldname != '';

are being used. Final result for text fields should be:

... AND ' . sql_isnotempty('tablename', 'fieldname', true/false, true/false);

and for varchar fields result should be:

... AND fieldname != :empty; "; $params['empty'] = '';

(see parameters description below)

Parameters
string$tablenameName of the table (without prefix). This is not used for now but can be necessary in the future if we want to use some introspection using meta information against the DB.
string$fieldnameThe name of the field we are going to check.
bool$nullablefieldSpecifies if the field is nullable (true) or not (false) in the DB.
bool$textfieldSpecifies if it is a text (also called clob) field (true) or a varchar one (false).
Return values
stringThe sql code to be added to check for non empty values.

◆ sql_length()

mysqli_native_moodle_database::sql_length (   $fieldname)
inherited

Returns the SQL text to be used to calculate the length in characters of one expression.

Parameters
stringfieldname or expression to calculate its length in characters.
Return values
stringthe piece of SQL code to be used in the statement.

Reimplemented from moodle_database.

◆ sql_like()

mysqli_native_moodle_database::sql_like (   $fieldname,
  $param,
  $casesensitive = true,
  $accentsensitive = true,
  $notlike = false,
  $escapechar = '\\' 
)
inherited

Returns 'LIKE' part of a query.

Note that mysql does not support $casesensitive = true and $accentsensitive = false. More information in http://bugs.mysql.com/bug.php?id=19567.

Parameters
string$fieldnameusually name of the table column
string$paramusually bound query parameter (?, :named)
bool$casesensitiveuse case sensitive search
bool$accensensitiveuse accent sensitive search (ignored if $casesensitive is true)
bool$notliketrue means "NOT LIKE"
string$escapecharescape char for '' and '_'
Return values
stringSQL code fragment

Reimplemented from moodle_database.

◆ sql_like_escape()

moodle_database::sql_like_escape (   $text,
  $escapechar = '\\' 
)
inherited

Escape sql LIKE special characters like '_' or ''.

Parameters
string$textThe string containing characters needing escaping.
string$escapecharThe desired escape character, defaults to '\'.
Return values
stringThe escaped sql LIKE string.

◆ sql_modulo()

moodle_database::sql_modulo (   $int1,
  $int2 
)
inherited

Returns the SQL text to be used in order to perform module '' operation - remainder after division.

Parameters
int$int1The first operand integer in the operation.
int$int2The second operand integer in the operation.
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented in oci_native_moodle_database.

◆ sql_null_from_clause()

moodle_database::sql_null_from_clause ( )
inherited

Returns the FROM clause required by some DBs in all SELECT statements.

To be used in queries not having FROM clause to provide cross_db Most DBs don't need it, hence the default is ''

Return values
string

Reimplemented in oci_native_moodle_database.

◆ sql_order_by_text()

moodle_database::sql_order_by_text (   $fieldname,
  $numchars = 32 
)
inherited

Returns the SQL text to be used to order by one TEXT (clob) column, because some RDBMS doesn't support direct ordering of such fields.

Note that the use or queries being ordered by TEXT columns must be minimised, because it's really slooooooow.

Parameters
string$fieldnameThe name of the TEXT field we need to order by.
int$numcharsThe number of chars to use for the ordering (defaults to 32).
Return values
stringThe piece of SQL code to be used in your statement.

Reimplemented in sqlsrv_native_moodle_database, and oci_native_moodle_database.

◆ sql_position()

moodle_database::sql_position (   $needle,
  $haystack 
)
inherited

Returns the SQL for returning searching one string for the location of another.

Note, there is no guarantee which order $needle, $haystack will be in the resulting SQL so when using this method, and both arguments contain placeholders, you should use named placeholders.

Parameters
string$needlethe SQL expression that will be searched for.
string$haystackthe SQL expression that will be searched in.
Return values
stringThe required searching SQL part.

Reimplemented in sqlsrv_native_moodle_database, and oci_native_moodle_database.

◆ sql_regex()

mysqli_native_moodle_database::sql_regex (   $positivematch = true,
  $casesensitive = false 
)
inherited

Return regex positive or negative match sql.

Parameters
bool$positivematch
bool$casesensitive
Return values
stringor empty if not supported

Reimplemented from moodle_database.

◆ sql_substr()

moodle_database::sql_substr (   $expr,
  $start,
  $length = false 
)
inherited

Returns the proper substr() SQL text used to extract substrings from DB NOTE: this was originally returning only function name.

Parameters
string$exprSome string field, no aggregates.
mixed$startInteger or expression evaluating to integer (1 based value; first char has index 1)
mixed$lengthOptional integer or expression evaluating to integer.
Return values
stringThe sql substring extraction fragment.

Reimplemented in sqlsrv_native_moodle_database.

◆ start_delegated_transaction()

moodle_database::start_delegated_transaction ( )
inherited

On DBs that support it, switch to transaction mode and begin a transaction you'll need to ensure you call allow_commit() on the returned object or your changes will be lost.

this is very useful for massive updates

Delegated database transactions can be nested, but only one actual database transaction is used for the outer-most delegated transaction. This method returns a transaction object which you should keep until the end of the delegated transaction. The actual database transaction will only be committed if all the nested delegated transactions commit successfully. If any part of the transaction rolls back then the whole thing is rolled back.

Return values
moodle_transaction

◆ store_settings()

moodle_database::store_settings (   $dbhost,
  $dbuser,
  $dbpass,
  $dbname,
  $prefix,
array  $dboptions = null 
)
protectedinherited

Store various database settings.

Parameters
string$dbhostThe database host.
string$dbuserThe database user to connect as.
string$dbpassThe password to use when connecting to the database.
string$dbnameThe name of the database being connected to.
mixed$prefixstring means moodle db prefix, false used for external databases where prefix not used
array$dboptionsdriver specific options
Return values
void

◆ transactions_forbidden()

moodle_database::transactions_forbidden ( )
inherited

This is a test that throws an exception if transaction in progress.

This test does not force rollback of active transactions.

Return values
void
Exceptions
dml_transaction_exceptionif stansaction active

◆ transactions_supported()

mariadb_native_moodle_database::transactions_supported ( )
protected

It is time to require transactions everywhere.

MyISAM is NOT supported!

Return values
bool

Reimplemented from mysqli_native_moodle_database.

◆ update_record()

mysqli_native_moodle_database::update_record (   $table,
  $dataobject,
  $bulk = false 
)
inherited

Update a record in a table.

$dataobject is an object containing needed data Relies on $dataobject having a variable "id" to specify the record to update

Parameters
string$tableThe database table to be checked against.
object$dataobjectAn object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified.
booltrue means repeated updates expected
Return values
booltrue
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ update_record_raw()

mysqli_native_moodle_database::update_record_raw (   $table,
  $params,
  $bulk = false 
)
inherited

Update record in database, as fast as possible, no safety checks, lobs not supported.

Parameters
string$tablename
mixed$paramsdata record as object or array
booltrue means repeated updates expected
Return values
booltrue
Exceptions
dml_exceptionA DML specific exception is thrown for any errors.

Reimplemented from moodle_database.

◆ update_temp_table_stats()

moodle_database::update_temp_table_stats ( )
inherited

Analyze the data in temporary tables to force statistics collection after bulk data loads.

Return values
void

◆ where_clause()

moodle_database::where_clause (   $table,
array  $conditions = null 
)
protectedinherited

Returns the SQL WHERE conditions.

Parameters
string$tableThe table name that these conditions will be validated against.
array$conditionsThe conditions to build the where clause. (must not contain numeric indexes)
Exceptions
dml_exception
Return values
arrayAn array list containing sql 'where' part and 'params'.

◆ where_clause_list()

moodle_database::where_clause_list (   $field,
array  $values 
)
protectedinherited

Returns SQL WHERE conditions for the ..._list group of methods.

Parameters
string$fieldthe name of a field.
array$valuesthe values field might take.
Return values
arrayAn array containing sql 'where' part and 'params'

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