function db_error_generic($query, $query_error, $msg)
{
    global $config;
    $email = false;
    if (@$config['Email']['admin_sqlerror_notify'] == "Y") {
        $email = array($config['Company']['site_administrator']);
    }
    if (DEBUG_MODE == 1 || DEBUG_MODE == 3) {
        echo '<div>INVALID SQL:' . htmlspecialchars($query_error) . "</div>\n";
        echo '<div>SQL QUERY FAILURE:' . htmlspecialchars($query) . "</div>\n";
        print_r(cw_get_backtrace());
        flush();
    }
    $do_log = DEBUG_MODE == 2 || DEBUG_MODE == 3;
    if ($email !== false || $do_log) {
        cw_log_add('SQL', $msg, true, 1, $email, !$do_log);
    }
}
function cw_error_handler($errno, $errstr, $errfile, $errline)
{
    static $hash_errors = array();
    if (!(ini_get("error_reporting") & $errno)) {
        return;
    }
    if (ini_get("display_errors") == 0 && ini_get("log_errors") == 0) {
        return;
    }
    if (ini_get("ignore_repeated_errors") == 1 && isset($hash_errors[$errno]) && isset($hash_errors[$errno][$errfile . ":" . $errline])) {
        return;
    }
    $date = date('d-M-Y H:i:s', cw_core_get_time());
    $errortypes = array(E_ERROR => "Error", E_WARNING => "Warning", E_PARSE => "Parsing Error", E_NOTICE => "Notice", E_CORE_ERROR => "Error", E_CORE_WARNING => "Warning", E_COMPILE_ERROR => "Error", E_COMPILE_WARNING => "Warning", E_USER_ERROR => "Error", E_USER_WARNING => "Warning", E_USER_NOTICE => "Notice", E_STRICT => "Runtime Notice");
    $errortype = isset($errortypes[$errno]) ? $errortypes[$errno] : "Unknown Error";
    if (ini_get("display_errors") != 0) {
        # Display error
        global $REQUEST_METHOD;
        if (empty($REQUEST_METHOD)) {
            echo "{$errortype}: {$errstr} in {$errfile} on line {$errline}\n";
        } else {
            echo "<b>{$errortype}</b>: {$errstr} in <b>{$errfile}</b> on line <b>{$errline}</b><br />\n";
        }
    }
    if (ini_get("log_errors") == 1 && ini_get("error_log") != '') {
        # Write error to file
        $bt = '';
        $bt = "\nREQUEST_URI: " . $_SERVER['REQUEST_URI'];
        $bt .= "\nBacktrace:\n\t" . implode("\n\t", cw_get_backtrace(1));
        error_log("[{$date}] {$errortype}: {$errstr} in {$errfile} on line {$errline} {$bt}\n", 3, ini_get("error_log"));
    }
    if (ini_get("ignore_repeated_errors") == 1) {
        if (!isset($hash_errors[$errno])) {
            $hash_errors[$errno] = array();
        }
        $hash_errors[$errno][$errfile . ":" . $errline] = true;
    }
}