예제 #1
0
/**
 * Delete one or more records from a table
 *
 * @uses $CFG
 * @uses $db
 * @param string $table The database table to be checked against.
 * @param string $select A fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria).
 * @return object A PHP standard object with the results from the SQL call.
 * @todo Verify return type.
 */
function delete_records_select($table, $select = '')
{
    global $CFG, $db;
    // Clear record_cache (whole table)
    if ($CFG->rcache === true) {
        rcache_unset_table($table);
    }
    if (defined('MDL_PERFDB')) {
        global $PERF;
        $PERF->dbqueries++;
    }
    if ($select) {
        $select = 'WHERE ' . $select;
    }
    $sql = 'DELETE FROM ' . $CFG->prefix . $table . ' ' . $select;
    $rs = $db->Execute($sql);
    if (!$rs) {
        debugging($db->ErrorMsg() . '<br /><br />' . s($sql));
        if (!empty($CFG->dblogerror)) {
            $debug = array_shift(debug_backtrace());
            error_log("SQL " . $db->ErrorMsg() . " in {$debug['file']} on line {$debug['line']}. STATEMENT:  {$sql}");
        }
        return false;
    }
    return $rs;
}
예제 #2
0
/**
 * Delete one or more records from a table
 *
 * @uses $CFG
 * @uses $db
 * @param string $table The database table to be checked against.
 * @param string $select A fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria).
 * @return object A PHP standard object with the results from the SQL call.
 * @todo Verify return type.
 */
function delete_records_select($table, $select = '')
{
    global $CFG, $db;
    // Clear record_cache (whole table)
    if ($CFG->rcache === true) {
        rcache_unset_table($table);
    }
    if (defined('MDL_PERFDB')) {
        global $PERF;
        $PERF->dbqueries++;
    }
    if ($select) {
        $select = 'WHERE ' . $select;
    }
    return $db->Execute('DELETE FROM ' . $CFG->prefix . $table . ' ' . $select);
}