Esempio n. 1
0
function driver_db_query($query)
{
    global $db_conn;
    static $reconnect_attempts = 0;
    $result = mysqli_query($db_conn, $query);
    if (empty($result)) {
        // Lost connection, try to reconnect (max - 3 times)
        if ((driver_db_errno() == 2013 || driver_db_errno() == 2006) && $reconnect_attempts < 3) {
            $db_conn = db_initiate(Registry::get('config.db_host'), Registry::get('config.db_user'), Registry::get('config.db_password'), Registry::get('config.db_name'));
            $reconnect_attempts++;
            $result = driver_db_query($query);
            // Assume that the table is broken
            // Try to repair
        } elseif (preg_match("/'(\\S+)\\.(MYI|MYD)/", driver_db_error(), $matches)) {
            $result = mysqli_query("REPAIR TABLE {$matches['1']}");
        }
    }
    return $result;
}
Esempio n. 2
0
/**
 * Display database error
 *
 * @param resource $result result, returned by database server
 * @param string $query SQL query, passed to server
 * @return mixed false if no error, dies with error message otherwise
 */
function db_error($result, $query)
{
    if (!empty($result) || driver_db_errno() == 0) {
        // it's ok
    } else {
        $error = array('message' => driver_db_error() . ' <b>(' . driver_db_errno() . ')</b>', 'query' => $query);
        if (Registry::get('runtime.database.skip_errors') == true) {
            Registry::push('runtime.database.errors', $error);
        } else {
            fn_error(debug_backtrace(), $error);
        }
    }
    return false;
}