Common Moodle programming mistakes
Feel free to add to this list.
Error handling of get_records() and its variants (e.g. get_records_sql())
A common usage of these functions is like this:
$records = get_records() or my_error_handler();...
The problem is, if the query is executed successfully but matches no records, get_records() returns false, the same as if there is an error. That triggers the error handling mechanism and might not be what you want.
Since get_records() and its variants cannot tell between these two cases, use them only if you are intentionally not checking for error or if you want to treat the case of no matched record as an error too. For other cases, use get_recordset() or its variants. These functions return an ADORecordSet object (if there is no error) or false (if there is an error).