Esempio n. 1
0
/**
 * cpg_db_query()
 *
 * Perform a database query
 *
 * @param $query
 * @param integer $link_id
 * @return
 **/
function cpg_db_query($query, $link_id = 0)
{
    global $CONFIG, $query_stats, $queries;
    $query_start = cpgGetMicroTime();
    if ($link_id) {
        $result = mysql_query($query, $link_id);
    } else {
        $result = mysql_query($query, $CONFIG['LINK_ID']);
    }
    $query_end = cpgGetMicroTime();
    if (isset($CONFIG['debug_mode']) && ($CONFIG['debug_mode'] == 1 || $CONFIG['debug_mode'] == 2)) {
        $duration = round($query_end - $query_start, 3);
        $query_stats[] = $duration;
        $queries[] = "{$query} ({$duration}s)";
    }
    if (!$result) {
        cpg_db_error("While executing query \"{$query}\" on {$link_id}");
    }
    return $result;
}
/**
 * cpg_db_query()
 *
 * Perform a database query
 *
 * @param $query
 * @param integer $link_id
 * @return
 **/
function cpg_db_query($query, $use_link_id = 0)
{
    global $CONFIG, $query_stats, $queries;
    if ($use_link_id) {
        $link_id = $use_link_id;
    } else {
        $link_id = $CONFIG['LINK_ID'];
    }
    $query_start = cpgGetMicroTime();
    $result = mysql_query($query, $link_id);
    $query_end = cpgGetMicroTime();
    if (!isset($CONFIG['debug_mode']) || $CONFIG['debug_mode'] == 1 || $CONFIG['debug_mode'] == 2) {
        $trace = debug_backtrace();
        $last = $trace[0];
        $localfile = str_replace(realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR, '', $last['file']);
        $duration = ($query_end - $query_start) * 1000;
        $query_stats[] = $duration;
        $queries[] = "{$query} [{$localfile}:{$last['line']}] (" . round($duration, 2) . " ms)";
    }
    if (!$result && !defined('UPDATE_PHP')) {
        $trace = debug_backtrace();
        $last = $trace[0];
        $localfile = str_replace(realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR, '', $last['file']);
        cpg_db_error("While executing query '{$query}' in {$localfile} on line {$last['line']}", $link_id);
    }
    return $result;
}