// SQL queries
function SQL_QUERY ($sqlString, $F, $L, $enableCodes = true) {
- // Trim SQL string
- $sqlString = trim($sqlString);
-
- // Link is up?
- if (!SQL_IS_LINK_UP()) {
- // We should not quietly ignore this!
- debug_report_bug(__FUNCTION__, __LINE__, sprintf("Cannot query database: sqlString=%s,file=%s,line=%s",
- $sqlString,
- basename($F),
- $L
- ));
+ // Do we have cache?
+ if (!isset($GLOBALS[__FUNCTION__][$sqlString])) {
+ // Trim SQL string
+ $sqlStringModified = trim($sqlString);
+
+ // Empty query string or link is not up?
+ if (empty($sqlStringModified)) {
+ // Empty SQL string!
+ debug_report_bug(__FUNCTION__, __LINE__, sprintf("SQL string is empty. Please fix this. file=%s, line=%s",
+ basename($F),
+ $L
+ ));
+ } elseif (!SQL_IS_LINK_UP()) {
+ // We should not quietly ignore this
+ debug_report_bug(__FUNCTION__, __LINE__, sprintf("Cannot query database: sqlString=%s,file=%s,line=%s",
+ $sqlStringModified,
+ basename($F),
+ $L
+ ));
+ }
- // Return 'false' because it has failed
- return false;
- } elseif (empty($sqlString)) {
- // Empty SQL string!
- debug_report_bug(__FUNCTION__, __LINE__, sprintf("SQL string is empty. Please fix this. file=%s, line=%s",
- basename($F),
- $L
- ));
+ // Remove \t, \n and \r from queries they may confuse some MySQL versions
+ $sqlStringModified = str_replace("\t", ' ', str_replace("\n", ' ', str_replace("\r", ' ', $sqlStringModified)));
- // This is invalid, of course
- return false;
- }
+ // Compile config entries out
+ $sqlStringModified = SQL_PREPARE_SQL_STRING($sqlStringModified, $enableCodes);
- // Remove \t, \n and \r from queries they may confuse some MySQL versions
- $sqlString = str_replace("\t", ' ', str_replace("\n", ' ', str_replace("\r", ' ', $sqlString)));
+ // Cache it and remember as last SQL query
+ $GLOBALS[__FUNCTION__][$sqlString] = $sqlStringModified;
+ $GLOBALS['last_sql'] = $sqlStringModified;
+ } else {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache used!');
- // Compile config entries out
- $GLOBALS['last_sql'] = SQL_PREPARE_SQL_STRING($sqlString, $enableCodes);
+ // Use cache (to save a lot function calls
+ $sqlString = $GLOBALS[__FUNCTION__][$sqlString];
+ }
// Starting time
$querytimeBefore = microtime(true);