// SQL queries
function SQL_QUERY ($sql_string, $F, $L) {
- global $OK;
-
// Link is up?
if (!SQL_IS_LINK_UP()) return false;
// Run SQL command
//* DEBUG: */ echo $sql_string."<br />\n";
$result = mysql_query($sql_string, SQL_GET_LINK())
- or addFatalMessage($F." (".$L."):".mysql_error()."<br />
+ or addFatalMessage(__FUNCTION__, __LINE__, $F." (".$L."):".mysql_error()."<br />
Query string:<br />
".$sql_string);
// Debug output
//* DEBUG: */ print "Query=<pre>".$sql_string."</pre>, affected=<strong>".SQL_AFFECTEDROWS()."</strong>, numrows=<strong>".SQL_NUMROWS($result)."</strong><br />\n";
-
- if (($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1") && (isBooleanConstantAndTrue('DEBUG_MODE')) && (isBooleanConstantAndTrue('DEBUG_SQL'))) {
+ if (($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1") && (isDebugModeEnabled()) && (isBooleanConstantAndTrue('DEBUG_SQL'))) {
//
// Debugging stuff...
//
$fp = fopen(constant('PATH')."inc/cache/mysql.log", 'a') or mxchange_die("Cannot write mysql.log!");
- if (!isset($OK)) {
+ if (!isset($GLOBALS['sql_first_entry'])) {
// Write first entry
fwrite($fp, "Module=".$GLOBALS['module']."\n");
- $OK = true;
+ $GLOBALS['sql_first_entry'] = true;
} // END - if
fwrite($fp, $F."(LINE=".$L."|NUM=".SQL_NUMROWS($result)."|AFFECTED=".SQL_AFFECTEDROWS()."|QUERYTIME:".$queryTime."): ".str_replace('\r', "", str_replace('\n', " ", $sql_string))."\n");
fclose($fp);
// SQL connect
function SQL_CONNECT ($host, $login, $password, $F, $L) {
// Try to connect
- $connect = mysql_connect($host, $login, $password) or addFatalMessage($F." (".$L."):".mysql_error());
+ $connect = mysql_connect($host, $login, $password) or addFatalMessage(__FUNCTION__, __LINE__, $F." (".$L."):".mysql_error());
// Set the link resource
SQL_SET_LINK($connect);
if (!SQL_IS_LINK_UP()) return false;
// Return the result
- return mysql_select_db($dbName, SQL_GET_LINK()) or addFatalMessage($F." (".$L."):".mysql_error());
+ return mysql_select_db($dbName, SQL_GET_LINK()) or addFatalMessage(__FUNCTION__, __LINE__, $F." (".$L."):".mysql_error());
}
// SQL close link
// Do we need to update cache/db counter?
//* DEBUG: */ echo "DB=".getConfig('db_hits').",CACHE=".getConfig('cache_hits')."<br />\n";
- if ((GET_EXT_VERSION("cache") >= "0.0.7") && (getConfig('db_hits') > 0) && (getConfig('cache_hits') > 0) && (is_object($GLOBALS['cache_instance']))) {
+ if ((GET_EXT_VERSION("cache") >= "0.0.7") && (getConfig('db_hits') > 0) && (getConfig('cache_hits') > 0) && (isCacheInstanceValid())) {
// Add new hits
incrementConfigEntry('db_hits', getConfig('db_hits_run'));
// Update counter for db/cache
- UPDATE_CONFIG(array("db_hits", "cache_hits"), array(bigintval(getConfig('db_hits')), bigintval(getConfig('cache_hits'))));
+ UPDATE_CONFIG(array("db_hits", "cache_hits"), array(getConfig(('db_hits')), getConfig(('cache_hits'))));
} // END - if
// Close database link and forget the link
- $close = mysql_close(SQL_GET_LINK()) or addFatalMessage($F." (".$L."):".mysql_error());
+ $close = mysql_close(SQL_GET_LINK()) or addFatalMessage(__FUNCTION__, __LINE__, $F." (".$L."):".mysql_error());
// Close link
SQL_SET_LINK(null);
}
// Escape a string for the database
-function SQL_ESCAPE ($str, $secureString=true,$strip=true) {
+function SQL_ESCAPE ($str, $secureString=true, $strip=true) {
// Secure string first? (which is the default behaviour!)
if ($secureString) {
// Then do it here
} // END - if
// Prepare the SQL statement
- $SQL = "SELECT `".implode("`, `", $columns)."` FROM `{!_MYSQL_PREFIX!}_%s` WHERE ``='%s' LIMIT 1";
+ $sql = "SELECT `".implode("`, `", $columns)."` FROM `{!_MYSQL_PREFIX!}_%s` WHERE ``='%s' LIMIT 1";
// Return the result
- return SQL_QUERY_ESC($SQL,
+ return SQL_QUERY_ESC($sql,
array(
bigintval($id),
$table,
// Setter for link
function SQL_SET_LINK ($link) {
+ // Is this a resource or null?
+ if ((!is_resource($link)) && (!is_null($link))) {
+ // This should never happen!
+ trigger_error(sprintf("link is not resource or null. Type: %s", gettype($link)));
+ } // END - if
+
// Set it
- $GLOABLS['sql_link'] = $link;
+ $GLOBALS['sql_link'] = $link;
}
// Checks if the link is up