- // Run SQL command
- $result = @mysql_query($sql_string, $link)
- or ADD_FATAL($F." (".$L."):".mysql_error()."<br />
-".MYSQL_QUERY_STRING."<br />
-".$sql_string);
+ // Remove \t, \n and \r from queries they may confuse some MySQL versions
+ $sqlStringModified = str_replace(array(chr(9), PHP_EOL, chr(13)), array(' ', ' ', ' '), $sqlStringModified);
+
+ // Compile config entries out
+ $sqlStringModified = SQL_PREPARE_SQL_STRING($sqlStringModified, $enableCodes);
+
+ // Cache it and remember as last SQL query
+ $GLOBALS[__FUNCTION__][$sqlString] = $sqlStringModified;
+ $GLOBALS['last_sql'] = $sqlStringModified;
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Stored cache: ' . $sqlStringModified);
+ } elseif (!SQL_IS_LINK_UP()) {
+ // Link went down while using cached SQL
+ reportBug(__FUNCTION__, __LINE__, 'Link went down while using cached SQL: sqlString=' . $sqlString . ',F=' . basename($F) . ',L=' . $L . ',enableCodes=' . intval($enableCodes));
+ } else {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache used: ' . $sqlString);
+
+ // Use cache (to save a lot function calls
+ $GLOBALS['last_sql'] = $GLOBALS[__FUNCTION__][$sqlString];
+
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache is: ' . $sqlString);
+ }