If you need information for previous Moodle version, take a look to the DML functions - pre 2.0 page.For a detailed reference of changes, see the migration docs.
Thus to assure consistent data, it appears to be best practice to ensure that your query include an "id column" as the first field.
(When developing custom tables, be sure to make id your first column for this reason!
) Get the first two columns from a number of records as an associative array where all the given conditions met.
You can choose the two fields or leave the parameter blank and the method will return the first two columns of the table. /** * 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.
* * @param string $table The database table to be inserted into * @param array|Traversable $dataobjects list of objects to be inserted, must be compatible with foreach * @return void does not return new record ids */ Where the number of records to be retrieved from DB is high, the get_records_xxx() functions above are far from optimal, because they load all the records in memory at the same time.
This page describes the functions available to access data in the Moodle database.
You should exclusively use these functions in order to retrieve or modify database content because these functions provide a high level of abstraction and guarantee that your database manipulation will work against different RDBMSes.
Where possible, tricks and examples will be documented here in order to make developers' lives a bit easier.
Of course, feel free to clarify, complete and add more information to this documentation. Important note: All the functions shown on this page are for use in Moodle 2.0 upwards, where we changed the DB layer to support some new features.