function vam_db_query($query, $link = 'db_link')
{
    global ${$link};
    global $query_counts;
    $query_counts++;
    //echo $query.'<br>';
    if (STORE_DB_TRANSACTIONS == 'true') {
        error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    }
    //    $queryStartTime = array_sum(explode(" ",microtime()));
    $result = mysql_query($query, ${$link}) or vam_db_error($query, mysql_errno(), mysql_error());
    //	$queryEndTime = array_sum(explode(" ",microtime()));
    //	$processTime = $queryEndTime - $queryStartTime;
    //	echo 'time: '.$processTime.' Query: '.$query.'<br>';
    if (STORE_DB_TRANSACTIONS == 'true') {
        $result_error = mysql_error();
        error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    }
    //Start VaM db-error processing
    if (!$result) {
        vam_db_error($query, mysql_errno(), mysql_error());
    }
    //End VaM db-error processing
    return $result;
}
function vam_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link', $use_pconnect = USE_PCONNECT, $new_link = false)
{
    global ${$link};
    if ($use_pconnect == 'true') {
        ${$link} = mysql_pconnect($server, $username, $password);
    } else {
        ${$link} = @mysql_connect($server, $username, $password, $new_link);
    }
    if (${$link}) {
        @mysql_select_db($database);
        @mysql_query("SET SQL_MODE= ''");
        @mysql_query("SET SQL_BIG_SELECTS=1");
        @mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");
    }
    //Start VaM db-error processing
    if (!${$link}) {
        vam_db_error("connect", mysql_errno(), mysql_error());
    }
    //End VaM db-error processing
    return ${$link};
}
function vam_db_queryCached($query, $link = 'db_link')
{
    global ${$link};
    // get HASH ID for filename
    $id = md5($query);
    // cache File Name
    $file = SQL_CACHEDIR . $id . '.vam';
    // file life time
    $expire = DB_CACHE_EXPIRE;
    // 24 hours
    if (STORE_DB_TRANSACTIONS == 'true') {
        error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    }
    if (file_exists($file) && filemtime($file) > time() - $expire) {
        // get cached resulst
        $result = unserialize(implode('', file($file)));
    } else {
        if (file_exists($file)) {
            @unlink($file);
        }
        // get result from DB and create new file
        $result = mysql_query($query, ${$link}) or vam_db_error($query, mysql_errno(), mysql_error());
        if (STORE_DB_TRANSACTIONS == 'true') {
            $result_error = mysql_error();
            error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
        }
        // fetch data into array
        while ($record = vam_db_fetch_array($result)) {
            $records[] = $record;
        }
        // safe result into file.
        $stream = serialize($records);
        $fp = fopen($file, "w");
        fwrite($fp, $stream);
        fclose($fp);
        $result = $records;
    }
    return $result;
}
Esempio n. 4
0
function service_vam_db_query($query, $link_service = 'db_link_service')
{
    global ${$link_service}, $logger_service;
    if (STORE_DB_TRANSACTIONS == 'true') {
        if (!is_object($logger_service)) {
            $logger_service = new logger_service();
        }
        $logger_service->write($query, 'QUERY');
    }
    $result = mysql_query($query, ${$link_service}) or vam_db_error($query, mysql_errno(), mysql_error());
    if (STORE_DB_TRANSACTIONS == 'true') {
        if (mysql_error()) {
            $logger_service->write(mysql_error(), 'ERROR');
        }
    }
    return $result;
}