Example #1
0
function is_db_connected()
{
    global $_OPENDB_DB_CONNECTED;
    if (!is_bool($_OPENDB_DB_CONNECTED)) {
        $_OPENDB_DB_CONNECTED = init_db_connection() !== FALSE;
    }
    return $_OPENDB_DB_CONNECTED;
}
Example #2
0
function mysqli_param_query($query, $params = false, $noFail = false)
{
    global $dblink;
    if (!$dblink) {
        // We may need a reinit for e.g. session closure
        init_db_connection();
    }
    if (!$params) {
        return mysqli_query_check($query, $noFail);
    }
    foreach ($params as &$v) {
        if (is_null($v)) {
            $v = 'NULL';
        } elseif (is_array($v)) {
            $t = '';
            foreach ($v as $v2) {
                if ($t) {
                    $t .= ',';
                }
                $v2 = mysqli_real_escape_string($dblink, $v2);
                if (!is_numeric($v2) || strlen(trim($v2)) > 0 && substr(trim($v2), 0, 1) == '0') {
                    $v2 = "'{$v2}'";
                }
                $t .= $v2;
            }
            $v = $t;
        } else {
            $v = mysqli_real_escape_string($dblink, $v);
            if (!is_numeric($v) || strlen(trim($v)) > 1 && substr(trim($v), 0, 1) == '0') {
                $v = "'{$v}'";
            }
        }
    }
    $sql_query = vsprintf(str_replace('?', '%s', $query), $params);
    return mysqli_query_check($sql_query, $noFail);
}
Example #3
0
function db_session_gc($maxlifetime)
{
    // hack - it seems that the db gets closed before the session info is written
    if (!db_ping()) {
        init_db_connection();
    }
    $query = "DELETE FROM php_session " . " WHERE expiration < " . time() - $maxlifetime;
    $result = db_query($query);
    if ($result && db_affected_rows() > 0) {
        return TRUE;
    } else {
        return FALSE;
    }
}