Moodle has a well-defined API that can be used to perform almost any database function that you need. You would almost never need to access any SQL commands directly. The API is contained in the /lib/dmllib.php
file (DM stands for Data Manipulation).
There are three types of get
functions for each of the three return types—fields, single records, and arrays of records. Each of these three types of functions specifies query information differently.
The first type of function passes all of the query information through the parameter list for each of the three return types. All three types of functions take the table name as the first argument. This is always specified without the prefix (if there is one).
The first type is as follows:
get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='')
This function returns a single field value, identified by the string $return
parameter. If...