+
+ // Starting time
+ $querytimeBefore = microtime(TRUE);
+
+ // Run SQL command
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . basename($file) . ',line=' . $line . ',sql=' . $GLOBALS['last_sql']);
+ $result = mysql_query($GLOBALS['last_sql'], getSqlLink())
+ or sqlError($file, $line, 'file='. basename($file) . ',line=' . $line . ':mysql_error()=' . mysql_error() . ',last_query=' . $GLOBALS['last_sql']);
+ //* DEBUG: */ logDebugMessage($file, $line, 'sql=' . $GLOBALS['last_sql'] . ',affected=' . sqlAffectedRows() . ',numRows='.(isValidSqlLink($result) ? sqlNumRows($result) : gettype($result)));
+
+ // Calculate query time
+ $queryTime = microtime(TRUE) - $querytimeBefore;
+
+ // Add this query to array including timing
+ addSqlToDebug($result, $GLOBALS['last_sql'], $queryTime, $file, $line);
+
+ // Save last successfull query
+ setConfigEntry('db_last_query', $GLOBALS['last_sql']);
+
+ // Count all query times
+ incrementConfigEntry('sql_time', $queryTime);
+
+ // Count this query
+ incrementConfigEntry('sql_count');
+
+ // Debug output
+ if (isSqlDebugEnabled()) {
+ // Is this the first call?
+ if (!isset($GLOBALS['sql_first_entry'])) {
+ // Write first entry
+ appendLineToFile(getCachePath() . 'mysql.log', 'Module=' . getModule());
+ $GLOBALS['sql_first_entry'] = TRUE;
+ } // END - if
+
+ // Append debug line
+ appendLineToFile(getCachePath() . 'mysql.log', basename($file) . '|LINE=' . $line . '|NUM=' . (isValidSqlLink($result) ? sqlNumRows($result) : 'false') . '|AFFECTED=' . sqlAffectedRows() . '|QUERYTIME:' . ($queryTime * 1000) . 'ms): ' . str_replace(array(chr(13), PHP_EOL), array('', ' '), $GLOBALS['last_sql']));
+ } // END - if
+
+ // Increment stats entry
+ incrementStatsEntry('db_hits');
+
+ // Return the result