function xtc_db_queryCached($query, $link = 'db_link') { global ${$link}; // get HASH ID for filename $id = md5($query); // cache File Name $file = SQL_CACHEDIR . $id . '.xtc'; // 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 = mysqli_query(${$link}, $query) or xtc_db_error($query, mysqli_errno(${$link}), mysqli_error(${$link})); if (STORE_DB_TRANSACTIONS == 'true') { $result_error = mysqli_error(${$link}); error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } // fetch data into array $records = array(); while ($record = xtc_db_fetch_array($result)) { $records[] = $record; } // safe result into file. $stream = serialize($records); $fp = fopen($file, "w"); fwrite($fp, $stream); fclose($fp); $result = unserialize(implode('', file($file))); } return $result; }
function xtc_db_query($query, $link = 'db_link') { global ${$link}; //echo $query.'<br />'; //BOF - DokuMan - 2010-02-25 - also check for defined STORE_DB_TRANSACTIONS constant //if (STORE_DB_TRANSACTIONS == 'true') { // error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); //} //EOF - DokuMan - 2010-02-25 - also check for defined STORE_DB_TRANSACTIONS constant // $queryStartTime = array_sum(explode(" ",microtime())); $result = mysqli_query(${$link}, $query) or xtc_db_error($query, mysqli_errno(${$link}), mysqli_error(${$link})); // $queryEndTime = array_sum(explode(" ",microtime())); // $processTime = $queryEndTime - $queryStartTime; // echo 'time: '.$processTime.' Query: '.$query.'<br />'; //BOF - DokuMan - 2010-02-25 - also check for defined STORE_DB_TRANSACTIONS constant //if (STORE_DB_TRANSACTIONS == 'true') { if (defined('STORE_DB_TRANSACTIONS') && STORE_DB_TRANSACTIONS == 'true') { error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); //EOF - DokuMan - 2010-02-25 - also check for defined STORE_DB_TRANSACTIONS constant $result_error = mysqli_error(${$link}); error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } return $result; }
function service_xtc_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 = mysqli_query(${$link_service}, $query) or xtc_db_error($query, mysqli_errno(${$link_service}), mysqli_error(${$link_service})); if (STORE_DB_TRANSACTIONS == 'true') { if (mysqli_error(${$link_service})) { $logger_service->write(mysqli_error(${$link_service}), 'ERROR'); } } return $result; }