|
Moodle
2.2.1
http://www.collinsharper.com
|

Public Member Functions | |
| __construct ($external=false) | |
| __destruct () | |
| driver_installed () | |
| get_prefix () | |
| get_dbfamily () | |
| get_name () | |
| get_configuration_help () | |
| get_configuration_hints () | |
| export_dbconfig () | |
| diagnose () | |
| connect ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) | |
| create_database ($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null) | |
| dispose () | |
| query_log ($error=false) | |
| get_server_info () | |
| get_last_error () | |
| get_in_or_equal ($items, $type=SQL_PARAMS_QM, $prefix='param', $equal=true, $onemptyitems=false) | |
| fix_sql_params ($sql, array $params=null) | |
| get_tables ($usecache=true) | |
| get_indexes ($table) | |
| get_columns ($table, $usecache=true) | |
| reset_caches () | |
| get_manager () | |
| change_db_encoding () | |
| setup_is_unicodedb () | |
| set_debug ($state) | |
| get_debug () | |
| set_logging ($state) | |
| change_database_structure ($sql) | |
| execute ($sql, array $params=null) | |
| get_recordset ($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_recordset_list ($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_recordset_select ($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_recordset_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0) | |
| get_records ($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_records_list ($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_records_select ($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_records_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0) | |
| get_records_menu ($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_records_select_menu ($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) | |
| get_records_sql_menu ($sql, array $params=null, $limitfrom=0, $limitnum=0) | |
| get_record ($table, array $conditions, $fields='*', $strictness=IGNORE_MISSING) | |
| get_record_select ($table, $select, array $params=null, $fields='*', $strictness=IGNORE_MISSING) | |
| get_record_sql ($sql, array $params=null, $strictness=IGNORE_MISSING) | |
| get_field ($table, $return, array $conditions, $strictness=IGNORE_MISSING) | |
| get_field_select ($table, $return, $select, array $params=null, $strictness=IGNORE_MISSING) | |
| get_field_sql ($sql, array $params=null, $strictness=IGNORE_MISSING) | |
| get_fieldset_select ($table, $return, $select, array $params=null) | |
| get_fieldset_sql ($sql, array $params=null) | |
| insert_record_raw ($table, $params, $returnid=true, $bulk=false, $customsequence=false) | |
| insert_record ($table, $dataobject, $returnid=true, $bulk=false) | |
| import_record ($table, $dataobject) | |
| update_record_raw ($table, $params, $bulk=false) | |
| update_record ($table, $dataobject, $bulk=false) | |
| set_field ($table, $newfield, $newvalue, array $conditions=null) | |
| set_field_select ($table, $newfield, $newvalue, $select, array $params=null) | |
| count_records ($table, array $conditions=null) | |
| count_records_select ($table, $select, array $params=null, $countitem="COUNT('x')") | |
| count_records_sql ($sql, array $params=null) | |
| record_exists ($table, array $conditions) | |
| record_exists_select ($table, $select, array $params=null) | |
| record_exists_sql ($sql, array $params=null) | |
| delete_records ($table, array $conditions=null) | |
| delete_records_list ($table, $field, array $values) | |
| delete_records_select ($table, $select, array $params=null) | |
| sql_null_from_clause () | |
| sql constructs | |
| sql_bitand ($int1, $int2) | |
| sql_bitnot ($int1) | |
| sql_bitor ($int1, $int2) | |
| sql_bitxor ($int1, $int2) | |
| sql_modulo ($int1, $int2) | |
| sql_ceil ($fieldname) | |
| sql_cast_char2int ($fieldname, $text=false) | |
| sql_cast_char2real ($fieldname, $text=false) | |
| sql_cast_2signed ($fieldname) | |
| sql_compare_text ($fieldname, $numchars=32) | |
| sql_like ($fieldname, $param, $casesensitive=true, $accentsensitive=true, $notlike=false, $escapechar= '\\') | |
| sql_like_escape ($text, $escapechar= '\\') | |
| sql_ilike () | |
| sql_concat () | |
| sql_concat_join ($separator="' '", $elements=array()) | |
| sql_fullname ($first='firstname', $last='lastname') | |
| sql_order_by_text ($fieldname, $numchars=32) | |
| sql_length ($fieldname) | |
| sql_substr ($expr, $start, $length=false) | |
| sql_position ($needle, $haystack) | |
| sql_empty () | |
| sql_isempty ($tablename, $fieldname, $nullablefield, $textfield) | |
| sql_isnotempty ($tablename, $fieldname, $nullablefield, $textfield) | |
| sql_regex_supported () | |
| sql_regex ($positivematch=true) | |
| is_transaction_started () | |
| transactions_forbidden () | |
| start_delegated_transaction () | |
| commit_delegated_transaction (moodle_transaction $transaction) | |
| rollback_delegated_transaction (moodle_transaction $transaction, Exception $e) | |
| force_transaction_rollback () | |
| session_lock_supported () | |
| session locking | |
| get_session_lock ($rowid, $timeout) | |
| release_session_lock ($rowid) | |
| perf_get_reads () | |
| performance and logging | |
| perf_get_writes () | |
| perf_get_queries () | |
Static Public Member Functions | |
| static | get_driver_instance ($type, $library, $external=false) |
Protected Member Functions | |
| get_dbtype () | |
| get_dblibrary () | |
| store_settings ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) | |
| query_start ($sql, array $params=null, $type, $extrainfo=null) | |
| query_end ($result) | |
| allowed_param_types () | |
| print_debug ($sql, array $params=null, $obj=null) | |
| where_clause ($table, array $conditions=null) | |
| where_clause_list ($field, array $values) | |
| fix_table_names ($sql) | |
| normalise_value ($column, $value) | |
| transactions_supported () | |
| transactions | |
| begin_transaction () | |
| commit_transaction () | |
| rollback_transaction () | |
Protected Attributes | |
| $database_manager | |
| $temptables | |
| $columns = array() | |
| $tables = null | |
| $dbhost | |
| $dbuser | |
| $dbpass | |
| $dbname | |
| $prefix | |
| $dboptions | |
| $external | |
| $reads = 0 | |
| $writes = 0 | |
| $debug = 0 | |
| $last_sql | |
| $last_params | |
| $last_type | |
| $last_extrainfo | |
| $last_time | |
| $used_for_db_sessions = false | |
Abstract class representing moodle database interface.
Definition at line 64 of file moodle_database.php.
| __construct | ( | $ | external = false | ) |
Constructor - instantiates the database, specifying if it's external (connect to other systems) or no (Moodle DB) note this has effect to decide if prefix checks must be performed or no
| bool | true means external database used |
Reimplemented in sqlsrv_native_moodle_database, and pdo_moodle_database.
Definition at line 132 of file moodle_database.php.
| __destruct | ( | ) |
Destructor - cleans up and flushes everything needed.
Definition at line 139 of file moodle_database.php.

| allowed_param_types | ( | ) | [abstract, protected] |
Returns supported query parameter types
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, mssql_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| begin_transaction | ( | ) | [abstract, protected] |
Driver specific start of real database transaction, this can not be used directly in code.
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| change_database_structure | ( | $ | sql | ) | [abstract] |
Do NOT use in code, to be used by database_manager only!
| string | $sql | query |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.
Attempt to change db encoding toUTF-8 if possible
Definition at line 887 of file moodle_database.php.
| commit_delegated_transaction | ( | moodle_transaction $ | transaction | ) |
Indicates delegated transaction finished successfully. The real database transaction is committed only if all delegated transactions committed.
Definition at line 2097 of file moodle_database.php.

| commit_transaction | ( | ) | [abstract, protected] |
Driver specific commit of real database transaction, this can not be used directly in code.
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

Connect to db Must be called before other methods.
| string | $dbhost | |
| string | $dbuser | |
| string | $dbpass | |
| string | $dbname | |
| mixed | $prefix | string means moodle db prefix, false used for external databases where prefix not used |
| array | $dboptions | driver specific options |
| dml_connection_exception | if error |
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.
| count_records | ( | $ | table, |
| array $ | conditions = null |
||
| ) |
Count the records in a table where all the given conditions met.
| string | $table | The table to query. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| dml_exception | if error |
Definition at line 1507 of file moodle_database.php.

| count_records_select | ( | $ | table, |
| $ | select, | ||
| array $ | params = null, |
||
| $ | countitem = "COUNT('x')" |
||
| ) |
Count the records in a table which match a particular WHERE clause.
| string | $table | The database table to be checked against. |
| string | $select | A fragment of SQL to be used in a WHERE clause in the SQL call. |
| array | $params | array of sql parameters |
| string | $countitem | The count string to be used in the SQL call. Default is COUNT('x'). |
| dml_exception | if error |
Definition at line 1522 of file moodle_database.php.


| count_records_sql | ( | $ | sql, |
| array $ | params = null |
||
| ) |
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.
| string | $sql | The SQL string you wish to be executed. |
| array | $params | array of sql parameters |
| dml_exception | if error |
Definition at line 1542 of file moodle_database.php.


| create_database | ( | $ | dbhost, |
| $ | dbuser, | ||
| $ | dbpass, | ||
| $ | dbname, | ||
| array $ | dboptions = null |
||
| ) |
Attempt to create the database
| string | $dbhost | |
| string | $dbuser | |
| string | $dbpass | |
| string | $dbname |
Reimplemented in sqlite3_pdo_moodle_database, and mysqli_native_moodle_database.
Definition at line 294 of file moodle_database.php.
| delete_records | ( | $ | table, |
| array $ | conditions = null |
||
| ) |
Delete the records from a table where all the given conditions met. If conditions not specified, table is truncated.
| string | $table | the table to delete from. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| dml_exception | if error |
Reimplemented in sqlite3_pdo_moodle_database.
Definition at line 1609 of file moodle_database.php.

| delete_records_list | ( | $ | table, |
| $ | field, | ||
| array $ | values | ||
| ) |
Delete the records from a table where one field match one list of values.
| string | $table | the table to delete from. |
| string | $field | The field to search |
| array | $values | array of values |
| dml_exception | if error |
Definition at line 1628 of file moodle_database.php.

| delete_records_select | ( | $ | table, |
| $ | select, | ||
| array $ | params = null |
||
| ) | [abstract] |
Delete one or more records from a table which match a particular WHERE clause.
| string | $table | The database table to be checked against. |
| string | $select | A fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria). |
| array | $params | array of sql parameters |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and pdo_moodle_database.

| diagnose | ( | ) |
Diagnose database and tables, this function is used to verify database and driver settings, db engine types, etc.
Reimplemented in mysqli_native_moodle_database, and oci_native_moodle_database.
Definition at line 248 of file moodle_database.php.
| dispose | ( | ) |
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 in mysqli_native_moodle_database, oci_native_moodle_database, mssql_native_moodle_database, sqlsrv_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 304 of file moodle_database.php.


| driver_installed | ( | ) | [abstract] |
Detects if all needed PHP stuff installed. Note: can be used before connect()
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.

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::execute_sql() instead!
| string | $sql | query |
| array | $params | query parameters |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| export_dbconfig | ( | ) |
Returns db related part of config.php
Definition at line 226 of file moodle_database.php.

| fix_sql_params | ( | $ | sql, |
| array $ | params = null |
||
| ) |
Normalizes sql query parameters and verifies parameters.
| string | $sql | query or part of it |
| array | $params | query parameters |
Definition at line 677 of file moodle_database.php.


| fix_table_names | ( | $ | sql | ) | [protected] |
Converts short table name {tablename} to real table name
| string | sql |
Reimplemented in oci_native_moodle_database, mssql_native_moodle_database, and sqlsrv_native_moodle_database.
Definition at line 661 of file moodle_database.php.

Force rollback of all delegated transaction. Does not trow any exceptions and does not log anything.
This method should be used only from default exception handlers and other core code.
Definition at line 2188 of file moodle_database.php.


| get_columns | ( | $ | table, |
| $ | usecache = true |
||
| ) | [abstract] |
Returns detailed information about columns in table. This information is cached internally.
| string | $table | name |
| bool | $usecache |
Reimplemented in moodle_database_for_testing, sqlsrv_native_moodle_database, oci_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and sqlite3_pdo_moodle_database.

| get_configuration_help | ( | ) | [abstract] |
Returns localised database configuration help. Note: can be used before connect()
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, pdo_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, and mssql_native_moodle_database.
| get_configuration_hints | ( | ) | [abstract] |
Returns localised database description Note: can be used before connect()
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, pdo_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, and mssql_native_moodle_database.
| get_dbfamily | ( | ) | [abstract] |
Returns database family type - describes SQL dialect Note: can be used before connect()
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.

| get_dblibrary | ( | ) | [abstract, protected] |
Returns general database library name Note: can be used before connect()
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, pdo_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, and mssql_native_moodle_database.

| get_dbtype | ( | ) | [abstract, protected] |
Returns more specific database driver type Note: can be used before connect()
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.

| get_debug | ( | ) |
Returns debug status
Reimplemented in moodle_database_for_testing.
Definition at line 912 of file moodle_database.php.

| static get_driver_instance | ( | $ | type, |
| $ | library, | ||
| $ | external = false |
||
| ) | [static] |
Loads and returns a database instance with the specified type and library.
| string | $type | database type of the driver (mysqli, pgsql, mssql, sqldrv, oci, etc.) |
| string | $library | database library of the driver (native, pdo, etc.) |
| boolean | $external | true if this is an external database |
Definition at line 166 of file moodle_database.php.

| get_field | ( | $ | table, |
| $ | return, | ||
| array $ | conditions, | ||
| $ | strictness = IGNORE_MISSING |
||
| ) |
Get a single field value from a table record where all the given conditions met.
| string | $table | the table to query. |
| string | $return | the field to return the value of. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| int | $strictness | IGNORE_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 |
| dml_exception | if error |
Definition at line 1328 of file moodle_database.php.

| 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.
| string | $table | the table to query. |
| string | $return | the field to return the value of. |
| string | $select | A fragment of SQL to be used in a where clause returning one row with one column |
| array | $params | array of sql parameters |
| int | $strictness | IGNORE_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 |
| dml_exception | if error |
Definition at line 1346 of file moodle_database.php.


| get_field_sql | ( | $ | sql, |
| array $ | params = null, |
||
| $ | strictness = IGNORE_MISSING |
||
| ) |
Get a single field value (first field) using a SQL statement.
| string | $table | the table to query. |
| string | $return | the field to return the value of. |
| string | $sql | The SQL query returning one row with one column |
| array | $params | array of sql parameters |
| int | $strictness | IGNORE_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 |
| dml_exception | if error |
Definition at line 1371 of file moodle_database.php.


| 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.
| string | $table | the table to query. |
| string | $return | the field we are intered in |
| string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
| array | $params | array of sql parameters |
| dml_exception | if error |
Definition at line 1390 of file moodle_database.php.

| get_fieldset_sql | ( | $ | sql, |
| array $ | params = null |
||
| ) | [abstract] |
Selects records and return values (first field) as an array using a SQL statement.
| string | $sql | The SQL query |
| array | $params | array of sql parameters |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, mysqli_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| get_in_or_equal | ( | $ | items, |
| $ | type = SQL_PARAMS_QM, |
||
| $ | prefix = 'param', |
||
| $ | equal = true, |
||
| $ | onemptyitems = false |
||
| ) |
Constructs IN() or = sql fragment
| mixed | $items | single or array of values |
| int | $type | bound param type SQL_PARAMS_QM or SQL_PARAMS_NAMED |
| string | $prefix | named parameter placeholder prefix (unique counter value is appended to each parameter name) |
| bool | $equal | true means equal, false not equal |
| mixed | $onemptyitems | defines the behavior when the array of items is empty. Defaults to false, meaning throw exceptions. Other values will become part of the returned SQL fragment. |
Definition at line 591 of file moodle_database.php.
| get_indexes | ( | $ | table | ) | [abstract] |
Return table indexes - everything lowercased
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and sqlite3_pdo_moodle_database.
| get_last_error | ( | ) | [abstract] |
Returns last error reported by database engine.
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, mssql_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| get_manager | ( | ) |
Returns sql generator used for db manipulation. Used mostly in upgrade.php scripts.
Definition at line 868 of file moodle_database.php.


| get_name | ( | ) | [abstract] |
Returns localised database type name Note: can be used before connect()
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, pdo_moodle_database, sqlsrv_native_moodle_database, oci_native_moodle_database, pgsql_native_moodle_database, and mssql_native_moodle_database.
| get_prefix | ( | ) |
Returns database table prefix Note: can be used before connect()
Definition at line 155 of file moodle_database.php.
| get_record | ( | $ | table, |
| array $ | conditions, | ||
| $ | fields = '*', |
||
| $ | strictness = IGNORE_MISSING |
||
| ) |
Get a single database record as an object where all the given conditions met.
| string | $table | The table to select from. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| string | $fields | A comma separated list of fields to be returned from the chosen table. |
| int | $strictness | IGNORE_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 |
| dml_exception | if error |
Definition at line 1247 of file moodle_database.php.

| 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.
| string | $table | The database table to be checked against. |
| string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
| array | $params | array of sql parameters |
| int | $strictness | IGNORE_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 |
| dml_exception | if error |
Definition at line 1264 of file moodle_database.php.


| get_record_sql | ( | $ | sql, |
| array $ | params = null, |
||
| $ | strictness = IGNORE_MISSING |
||
| ) |
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!
| string | $sql | The SQL string you wish to be executed, should normally only return one record. |
| array | $params | array of sql parameters |
| int | $strictness | IGNORE_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 |
| dml_exception | if error |
Reimplemented in oci_native_moodle_database.
Definition at line 1290 of file moodle_database.php.


| 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.
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.
| string | $table | the table to query. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
| string | $fields | a 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 | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Definition at line 1076 of file moodle_database.php.


| 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.
Return value as for
| string | $table | The database table to be checked against. |
| string | $field | The field to search |
| string | $values | array of values |
| string | $sort | Sort order (as valid SQL sort parameter) |
| string | $fields | A 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. |
| dml_exception | if error |
Definition at line 1096 of file moodle_database.php.

| 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.
Arguments as for
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.
| string | $table | the table to query. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
| string | $fields | a comma separated list of fields to return - the number of fields should be 2! |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Definition at line 1167 of file moodle_database.php.

| 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.
Return value as for
| string | $table | the table to query. |
| string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
| array | $params | array of sql parameters |
| string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
| string | $fields | a 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 | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Definition at line 1122 of file moodle_database.php.


| 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.
Arguments as for
| string | $table | The database table to be checked against. |
| string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
| array | $params | array of sql parameters |
| string | $sort | Sort order (optional) - a valid SQL order parameter |
| string | $fields | A comma separated list of fields to be returned from the chosen table - the number of fields should be 2! |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Definition at line 1196 of file moodle_database.php.

| get_records_sql | ( | $ | sql, |
| array $ | params = null, |
||
| $ | limitfrom = 0, |
||
| $ | limitnum = 0 |
||
| ) | [abstract] |
Get a number of records as an array of objects using a SQL statement.
Return value as for
| string | $sql | the 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 | $params | array of sql parameters |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| 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.
Arguments as for
| string | $sql | The SQL string you wish to be executed. |
| array | $params | array of sql parameters |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Definition at line 1222 of file moodle_database.php.

| 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.
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.
| string | $table | the table to query. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
| string | $fields | a comma separated list of fields to return (optional, by default all fields are returned). |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Definition at line 977 of file moodle_database.php.

| 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.
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 as for
| string | $table | the table to query. |
| string | $field | a field to check (optional). |
| array | $values | array of values the field must have |
| string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
| string | $fields | a comma separated list of fields to return (optional, by default all fields are returned). |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Fake condition, won't return rows ever. MDL-17645
Definition at line 1000 of file moodle_database.php.

| 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.
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 as for
| string | $table | the table to query. |
| string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
| array | $params | array of sql parameters |
| string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
| string | $fields | a comma separated list of fields to return (optional, by default all fields are returned). |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Definition at line 1027 of file moodle_database.php.


| get_recordset_sql | ( | $ | sql, |
| array $ | params = null, |
||
| $ | limitfrom = 0, |
||
| $ | limitnum = 0 |
||
| ) | [abstract] |
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 as for
| string | $sql | the SQL select query to execute. |
| array | $params | array of sql parameters |
| int | $limitfrom | return a subset of records, starting at this point (optional, required if $limitnum is set). |
| int | $limitnum | return a subset comprising this many records (optional, required if $limitfrom is set). |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| get_server_info | ( | ) | [abstract] |
Returns database server info array
Reimplemented in moodle_database_for_testing, mysqli_native_moodle_database, oci_native_moodle_database, mssql_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.
| get_session_lock | ( | $ | rowid, |
| $ | timeout | ||
| ) |
Obtain session lock
| int | $rowid | id of the row with session record |
| int | $timeout | max allowed time to wait for the lock in seconds |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 2217 of file moodle_database.php.
| get_tables | ( | $ | usecache = true | ) | [abstract] |
Return tables in database WITHOUT current prefix
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and sqlite3_pdo_moodle_database.
| import_record | ( | $ | table, |
| $ | dataobject | ||
| ) | [abstract] |
Import a record into a table, id field is required. Safety checks are NOT carried out. Lobs are supported.
| string | $table | name of database table to be inserted into |
| object | $dataobject | A data object with values for one or more fields in the record |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.
| insert_record | ( | $ | table, |
| $ | dataobject, | ||
| $ | returnid = true, |
||
| $ | bulk = false |
||
| ) | [abstract] |
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
| string | $table | The database table to be inserted into |
| object | $data | A data object with values for one or more fields in the record |
| bool | $returnid | Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned. |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

| insert_record_raw | ( | $ | table, |
| $ | params, | ||
| $ | returnid = true, |
||
| $ | bulk = false, |
||
| $ | customsequence = false |
||
| ) | [abstract] |
Insert new record into database, as fast as possible, no safety checks, lobs not supported.
| string | $table | name |
| mixed | $params | data record as object or array |
| bool | $returnit | return it of inserted record |
| bool | $bulk | true means repeated inserts expected |
| bool | $customsequence | true if 'id' included in $params, disables $returnid |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, mysqli_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.
Returns true if transaction in progress
Definition at line 2043 of file moodle_database.php.

| normalise_value | ( | $ | column, |
| $ | value | ||
| ) | [abstract, protected] |
Normalise values based in RDBMS dependencies (booleans, LOBs...)
| database_column_info | $column | column metadata corresponding with the value we are going to normalise |
| mixed | $value | value we are going to normalise |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, mysqli_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and sqlite3_pdo_moodle_database.
| perf_get_queries | ( | ) |
Returns number of queries done by this database
Definition at line 2250 of file moodle_database.php.
| perf_get_reads | ( | ) |
performance and logging
Returns number of reads done by this database
Definition at line 2234 of file moodle_database.php.
| perf_get_writes | ( | ) |
Returns number of writes done by this database
Definition at line 2242 of file moodle_database.php.
| print_debug | ( | $ | sql, |
| array $ | params = null, |
||
| $ | obj = null |
||
| ) | [protected] |
Print sql debug info
| string | $sql | query which caused problems |
| array | $params | optional query parameters |
| mixed | $obj | optional library specific object |
Definition at line 470 of file moodle_database.php.


| query_end | ( | $ | result | ) | [protected] |
Called immediately after each db query.
| mixed | db specific result |
Reimplemented in mssql_native_moodle_database, sqlsrv_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 370 of file moodle_database.php.


| query_log | ( | $ | error = false | ) |
Log last database query if requested
| mixed | string error or false if not error |
Definition at line 409 of file moodle_database.php.


| query_start | ( | $ | sql, |
| array $ | params = null, |
||
| $ | type, | ||
| $ | extrainfo = null |
||
| ) | [protected] |
Called before each db query.
| string | $sql | |
| array | array of parameters | |
| int | $type | type of query |
| mixed | $extrainfo | driver specific extra information |
Reimplemented in pdo_moodle_database, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 341 of file moodle_database.php.


| record_exists | ( | $ | table, |
| array $ | conditions | ||
| ) |
Test whether a record exists in a table where all the given conditions met.
The record to test is specified by giving up to three fields that must equal the corresponding values.
| string | $table | The table to check. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| dml_exception | if error |
Definition at line 1561 of file moodle_database.php.

| record_exists_select | ( | $ | table, |
| $ | select, | ||
| array $ | params = null |
||
| ) |
Test whether any records exists in a table which match a particular WHERE clause.
| string | $table | The database table to be checked against. |
| string | $select | A fragment of SQL to be used in a WHERE clause in the SQL call. |
| array | $params | array of sql parameters |
| dml_exception | if error |
Definition at line 1575 of file moodle_database.php.


| record_exists_sql | ( | $ | sql, |
| array $ | params = null |
||
| ) |
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.
| string | $sql | The SQL statement to execute. |
| array | $params | array of sql parameters |
| dml_exception | if error |
Definition at line 1593 of file moodle_database.php.


| release_session_lock | ( | $ | rowid | ) |
Release session lock
| int | $rowid | id of the row with session record |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 2226 of file moodle_database.php.
| reset_caches | ( | ) |
Reset internal column details cache
| string | $table | - empty means all, or one if name of table given |
Definition at line 858 of file moodle_database.php.

| rollback_delegated_transaction | ( | moodle_transaction $ | transaction, |
| Exception $ | e | ||
| ) |
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.
| moodle_transaction | $transaction | |
| Exception | $e | exception that caused the problem |
Definition at line 2144 of file moodle_database.php.

| rollback_transaction | ( | ) | [abstract, protected] |
Driver specific abort of real database transaction, this can not be used directly in code.
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.

session locking
Is session lock supported in this driver?
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 2207 of file moodle_database.php.
| set_debug | ( | $ | state | ) |
Enable/disable very detailed debugging
| bool | $state |
Reimplemented in moodle_database_for_testing.
Definition at line 904 of file moodle_database.php.
Set a single field in every table record where all the given conditions met.
| string | $table | The database table to be checked against. |
| string | $newfield | the field to set. |
| string | $newvalue | the value to set the field to. |
| array | $conditions | optional array $fieldname=>requestedvalue with AND in between |
| dml_exception | if error |
Definition at line 1480 of file moodle_database.php.

| set_field_select | ( | $ | table, |
| $ | newfield, | ||
| $ | newvalue, | ||
| $ | select, | ||
| array $ | params = null |
||
| ) | [abstract] |
Set a single field in every table record which match a particular WHERE clause.
| string | $table | The database table to be checked against. |
| string | $newfield | the field to set. |
| string | $newvalue | the value to set the field to. |
| string | $select | A fragment of SQL to be used in a where clause in the SQL call. |
| array | $params | array of sql parameters |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, mssql_native_moodle_database, and pdo_moodle_database.

| set_logging | ( | $ | state | ) |
Enable/disable detailed sql logging
| bool | $state |
Reimplemented in moodle_database_for_testing.
Definition at line 920 of file moodle_database.php.
Is db in unicode mode?
Reimplemented in oci_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 895 of file moodle_database.php.
| sql_bitand | ( | $ | int1, |
| $ | int2 | ||
| ) |
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!!
| int | $int1 | first integer in the operation |
| int | $int2 | second integer in the operation |
Reimplemented in oci_native_moodle_database.
Definition at line 1673 of file moodle_database.php.
| sql_bitnot | ( | $ | int1 | ) |
Returns the SQL text to be used in order to perform one bitwise NOT operation with 1 integer.
| int | $int1 | integer in the operation |
Reimplemented in oci_native_moodle_database.
Definition at line 1684 of file moodle_database.php.
| sql_bitor | ( | $ | int1, |
| $ | int2 | ||
| ) |
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!!
| int | $int1 | first integer in the operation |
| int | $int2 | second integer in the operation |
Reimplemented in oci_native_moodle_database.
Definition at line 1699 of file moodle_database.php.
| sql_bitxor | ( | $ | int1, |
| $ | int2 | ||
| ) |
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!!
| int | $int1 | first integer in the operation |
| int | $int2 | second integer in the operation |
Reimplemented in oci_native_moodle_database, pgsql_native_moodle_database, and sqlite3_pdo_moodle_database.
Definition at line 1714 of file moodle_database.php.
| sql_cast_2signed | ( | $ | fieldname | ) |
Returns the SQL to be used in order to an UNSIGNED INTEGER column to SIGNED.
(Only MySQL needs this. MySQL things that 1 * -1 = 18446744073709551615 if the 1 comes from an unsigned column).
| string | $fieldname | the name of the field to be cast |
Reimplemented in mysqli_native_moodle_database.
Definition at line 1778 of file moodle_database.php.
| sql_cast_char2int | ( | $ | fieldname, |
| $ | text = false |
||
| ) |
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!
| string | $fieldname | the name of the field to be casted |
| bool | $text | to specify if the original column is one TEXT (CLOB) column (true). Defaults to false. |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mysqli_native_moodle_database, and mssql_native_moodle_database.
Definition at line 1751 of file moodle_database.php.
| sql_cast_char2real | ( | $ | fieldname, |
| $ | text = false |
||
| ) |
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!
| string | $fieldname | the name of the field to be casted |
| bool | $text | to specify if the original column is one TEXT (CLOB) column (true). Defaults to false. |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, pgsql_native_moodle_database, mysqli_native_moodle_database, and mssql_native_moodle_database.
Definition at line 1765 of file moodle_database.php.
| sql_ceil | ( | $ | fieldname | ) |
Returns the correct CEIL expression applied to fieldname.
| string | $fieldname | the field (or expression) we are going to ceil |
Reimplemented in sqlsrv_native_moodle_database, and mssql_native_moodle_database.
Definition at line 1737 of file moodle_database.php.
| 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.
| string | $fieldname | the name of the TEXT field we need to order by |
| int | $numchars | of chars to use for the ordering (defaults to 32) |
Definition at line 1791 of file moodle_database.php.


| sql_concat | ( | ) | [abstract] |
Returns the proper SQL to do CONCAT between the elements passed Can take many parameters
This function accepts variable number of string parameters.
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, pdo_moodle_database, and sqlite3_pdo_moodle_database.

| sql_concat_join | ( | $ | separator = "' '", |
| $ | elements = array() |
||
| ) | [abstract] |
Returns the proper SQL to do CONCAT between the elements passed with a given separator
| string | $separator | |
| array | $elements |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, pgsql_native_moodle_database, pdo_moodle_database, and sqlite3_pdo_moodle_database.
| sql_empty | ( | ) |
Returns the empty string char used by every supported DB. To be used when we are searching for that values in our queries. Only Oracle uses this for now (will be out, once we migrate to proper NULLs if that days arrives)
Reimplemented in oci_native_moodle_database.
Definition at line 1939 of file moodle_database.php.
| sql_fullname | ( | $ | first = 'firstname', |
| $ | last = 'lastname' |
||
| ) |
Returns the proper SQL (for the dbms in use) to concatenate $firstname and $lastname TODO: Does this really need to be here? Eloy 20070727. TODO: we definitely do not! (skodak)
| string | $first | User's first name |
| string | $last | User's last name |
Definition at line 1871 of file moodle_database.php.

| sql_ilike | ( | ) |
Returns the proper SQL to do LIKE in a case-insensitive way.
Note the LIKE are case sensitive for Oracle. Oracle 10g is required to use the case insensitive search using regexp_like() or NLS_COMP=LINGUISTIC :-( See http://docs.moodle.org/en/XMLDB_Problems#Case-insensitive_searches
Reimplemented in pgsql_native_moodle_database.
Definition at line 1837 of file moodle_database.php.

| sql_isempty | ( | $ | tablename, |
| $ | fieldname, | ||
| $ | nullablefield, | ||
| $ | textfield | ||
| ) |
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 should be:
... AND ' . sql_isempty('tablename', 'fieldname', true/false, true/false);
(see parameters description below)
| string | $tablename | name 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 | $fieldname | name of the field we are going to check |
| boolean | $nullablefield | to specify if the field us nullable (true) or no (false) in the DB |
| boolean | $textfield | to specify if it is a text (also called clob) field (true) or a varchar one (false) |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, and mssql_native_moodle_database.
Definition at line 1972 of file moodle_database.php.

| sql_isnotempty | ( | $ | tablename, |
| $ | fieldname, | ||
| $ | nullablefield, | ||
| $ | textfield | ||
| ) |
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 should be:
... AND ' . sql_isnotempty('tablename', 'fieldname', true/false, true/false);
(see parameters description below)
| string | $tablename | name 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 | $fieldname | name of the field we are going to check |
| boolean | $nullablefield | to specify if the field us nullable (true) or no (false) in the DB |
| boolean | $textfield | to specify if it is a text (also called clob) field (true) or a varchar one (false) |
Definition at line 2002 of file moodle_database.php.

| sql_length | ( | $ | fieldname | ) |
Returns the SQL text to be used to calculate the length in characters of one expression.
| string | $fieldname | or expression to calculate its length in characters. |
Reimplemented in sqlsrv_native_moodle_database, mssql_native_moodle_database, and mysqli_native_moodle_database.
Definition at line 1895 of file moodle_database.php.
| sql_like | ( | $ | fieldname, |
| $ | param, | ||
| $ | casesensitive = true, |
||
| $ | accentsensitive = true, |
||
| $ | notlike = false, |
||
| $ | escapechar = '\\' |
||
| ) |
Returns 'LIKE' part of a query.
| string | $fieldname | usually name of the table column |
| string | $param | usually bound query parameter (?, :named) |
| bool | $casesensitive | use case sensitive search |
| bool | $accensensitive | use accent sensitive search (not all databases support accent insensitive) |
| bool | $notlike | true means "NOT LIKE" |
| string | $escapechar | escape char for '' and '_' |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, mssql_native_moodle_database, mysqli_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 1806 of file moodle_database.php.

| sql_like_escape | ( | $ | text, |
| $ | escapechar = '\\' |
||
| ) |
Escape sql LIKE special characters.
| string | $text | |
| string | $escapechar |
Definition at line 1821 of file moodle_database.php.
| sql_modulo | ( | $ | int1, |
| $ | int2 | ||
| ) |
Returns the SQL text to be used in order to perform module '' operation - remainder after division
| int | $int1 | first integer in the operation |
| int | $int2 | second integer in the operation |
Reimplemented in oci_native_moodle_database.
Definition at line 1726 of file moodle_database.php.
sql constructs
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 ''
Reimplemented in oci_native_moodle_database.
Definition at line 1658 of file moodle_database.php.
| 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.
Note that the use or queries being ordered by TEXT columns must be minimised, because it's really slooooooow.
| string | $fieldname | the name of the TEXT field we need to order by |
| string | $numchars | of chars to use for the ordering (defaults to 32) |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, and mssql_native_moodle_database.
Definition at line 1886 of file moodle_database.php.

| sql_position | ( | $ | needle, |
| $ | haystack | ||
| ) |
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.
| string | $needle | the SQL expression that will be searched for. |
| string | $haystack | the SQL expression that will be searched in. |
Reimplemented in oci_native_moodle_database, sqlsrv_native_moodle_database, and mssql_native_moodle_database.
Definition at line 1928 of file moodle_database.php.
Return regex positive or negative match sql
| bool | $positivematch |
Reimplemented in mysqli_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 2019 of file moodle_database.php.
Does this driver suppoer regex syntax when searching
Reimplemented in mysqli_native_moodle_database, and pgsql_native_moodle_database.
Definition at line 2010 of file moodle_database.php.
| 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
| string | $expr | some string field, no aggregates |
| mixed | $start | integer or expression evaluating to int (1 based value; first char has index 1) |
| mixed | $length | optional integer or expression evaluating to int |
Reimplemented in moodle_database_for_testing, sqlsrv_native_moodle_database, and mssql_native_moodle_database.
Definition at line 1908 of file moodle_database.php.
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.
Definition at line 2075 of file moodle_database.php.

| store_settings | ( | $ | dbhost, |
| $ | dbuser, | ||
| $ | dbpass, | ||
| $ | dbname, | ||
| $ | prefix, | ||
| array $ | dboptions = null |
||
| ) | [protected] |
Store various database settings
| string | $dbhost | |
| string | $dbuser | |
| string | $dbpass | |
| string | $dbname | |
| mixed | $prefix | string means moodle db prefix, false used for external databases where prefix not used |
| array | $dboptions | driver specific options |
Definition at line 276 of file moodle_database.php.

Throws exception if transaction in progress. This test does not force rollback of active transactions.
Definition at line 2052 of file moodle_database.php.

| transactions_supported | ( | ) | [protected] |
transactions
Are transactions supported? It is not responsible to run productions servers on databases without transaction support ;-)
Override in driver if needed.
Reimplemented in mysqli_native_moodle_database.
Definition at line 2034 of file moodle_database.php.
| update_record | ( | $ | table, |
| $ | dataobject, | ||
| $ | bulk = false |
||
| ) | [abstract] |
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
| string | $table | The database table to be checked against. |
| object | $dataobject | An object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified. |
| bool | true means repeated updates expected |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.
| update_record_raw | ( | $ | table, |
| $ | params, | ||
| $ | bulk = false |
||
| ) | [abstract] |
Update record in database, as fast as possible, no safety checks, lobs not supported.
| string | $table | name |
| mixed | $params | data record as object or array |
| bool | true means repeated updates expected |
| dml_exception | if error |
Reimplemented in moodle_database_for_testing, oci_native_moodle_database, sqlsrv_native_moodle_database, mysqli_native_moodle_database, mssql_native_moodle_database, pgsql_native_moodle_database, and pdo_moodle_database.
| where_clause | ( | $ | table, |
| array $ | conditions = null |
||
| ) | [protected] |
Returns SQL WHERE conditions.
| string | $table | - the table name that these conditions will be validated against. |
| array | conditions - must not contain numeric indexes |
Definition at line 497 of file moodle_database.php.


| where_clause_list | ( | $ | field, |
| array $ | values | ||
| ) | [protected] |
Returns SQL WHERE conditions for the ..._list methods.
| string | $field | the name of a field. |
| array | $values | the values field might take. |
Definition at line 562 of file moodle_database.php.

$columns = array() [protected] |
Definition at line 71 of file moodle_database.php.
$database_manager [protected] |
Definition at line 67 of file moodle_database.php.
$dbhost [protected] |
Definition at line 77 of file moodle_database.php.
$dbname [protected] |
Definition at line 83 of file moodle_database.php.
$dboptions [protected] |
Definition at line 88 of file moodle_database.php.
$dbpass [protected] |
Definition at line 81 of file moodle_database.php.
$dbuser [protected] |
Definition at line 79 of file moodle_database.php.
$debug = 0 [protected] |
Definition at line 99 of file moodle_database.php.
$external [protected] |
Definition at line 91 of file moodle_database.php.
$last_extrainfo [protected] |
Definition at line 108 of file moodle_database.php.
$last_params [protected] |
Definition at line 104 of file moodle_database.php.
$last_sql [protected] |
Definition at line 102 of file moodle_database.php.
$last_time [protected] |
Definition at line 110 of file moodle_database.php.
$last_type [protected] |
Definition at line 106 of file moodle_database.php.
$prefix [protected] |
Reimplemented in moodle_database_for_testing.
Definition at line 85 of file moodle_database.php.
$reads = 0 [protected] |
Definition at line 94 of file moodle_database.php.
$tables = null [protected] |
Definition at line 73 of file moodle_database.php.
$temptables [protected] |
Reimplemented in sqlsrv_native_moodle_database.
Definition at line 69 of file moodle_database.php.
$used_for_db_sessions = false [protected] |
Definition at line 115 of file moodle_database.php.
$writes = 0 [protected] |
Definition at line 96 of file moodle_database.php.