db_support
class db_support
| internal |
Wrapper for Moodle's global database object ($DB).
Provides a clean interface for database operations, allowing for better testability and isolation of Moodle's global state.
Methods
Retrieves a single database record as an object.
Retrieves a single field value from a database record.
Retrieves a single field value using a custom SQL query.
Retrieves multiple database records as an array of objects.
Retrieves records using a custom SQL query.
Inserts a new record into a table.
Updates an existing record in a table.
Deletes records from a table.
Checks if a record exists in a table.
Starts a delegated database transaction.
Executes a SQL query (for non-SELECT queries).
Retrieves the SQL fragment for matching a full name.
Retrieves the SQL fragment for a LIKE clause.
Retrieves an IN or EQUAL SQL fragment.
No description
Retrieves a recordset using a custom SQL query.
Retrieves the SQL fragment for comparing text fields.
Counts records in a table.
Details
at line 47
static stdClass|null
get_record(string $table, array $conditions, string $fields = '*', int $strictness = IGNORE_MISSING)
Retrieves a single database record as an object.
at line 68
static mixed
get_field(string $table, string $return, array $conditions, int $strictness = IGNORE_MISSING)
Retrieves a single field value from a database record.
at line 85
static mixed
get_field_sql(string $sql, array|null $params = null)
Retrieves a single field value using a custom SQL query.
at line 106
static array
get_records(string $table, array $conditions = [], string $sort = '', string $fields = '*', int $limitfrom = 0, int $limitnum = 0)
Retrieves multiple database records as an array of objects.
at line 125
static array
get_records_sql(string $sql, array|null $params = null, int $limitfrom = 0, int $limitnum = 0)
Retrieves records using a custom SQL query.
at line 144
static int
insert_record(string $table, stdClass $dataobject, bool $returnid = true, bool $bulk = false)
Inserts a new record into a table.
at line 162
static bool
update_record(string $table, stdClass $dataobject, bool $bulk = false)
Updates an existing record in a table.
at line 179
static bool
delete_records(string $table, array $conditions = [])
Deletes records from a table.
at line 196
static bool
record_exists(string $table, array $conditions)
Checks if a record exists in a table.
at line 208
static moodle_transaction
start_delegated_transaction()
Starts a delegated database transaction.
at line 225
static bool
execute(string $sql, array|null $params = null)
Executes a SQL query (for non-SELECT queries).
at line 240
static string
sql_fullname(string $firstname = 'firstname', string $lastname = 'lastname')
Retrieves the SQL fragment for matching a full name.
at line 259
static string
sql_like(string $field, string $param, bool $casesensitive = true, bool $accentsensitive = true, bool $notlike = false, string $escapechar = '\\')
Retrieves the SQL fragment for a LIKE clause.
at line 283
static array
get_in_or_equal(mixed $items, int $type = SQL_PARAMS_NAMED, string $prefix = 'p', bool $equal = true, mixed $onemptyitems = false)
Retrieves an IN or EQUAL SQL fragment.
at line 307
static array
get_records_menu(string $table, array $conditions = [], string $sort = '', string $fields = '*')
No description
at line 326
static moodle_recordset
get_recordset_sql(string $sql, array|null $params = null, int $limitfrom = 0, int $limitnum = 0)
Retrieves a recordset using a custom SQL query.
at line 340
static string
sql_compare_text(string $fieldname)
Retrieves the SQL fragment for comparing text fields.
at line 357
static int
count_records(string $table, array $conditions = [])
Counts records in a table.