// Remove \t, \n and \r from queries they may confuse some MySQL version I have heard
$sql_string = str_replace("\t", " ", str_replace("\n", " ", str_replace("\r", " ", $sql_string)));
- // Starting time
- $querytimeBefore = array_sum(explode(' ', microtime()));
-
// Replace {!_MYSQL_PREFIX!} with constant, closes #84. Thanks to profi-concept
$sql_string = str_replace("{!_MYSQL_PREFIX!}", constant('_MYSQL_PREFIX'), $sql_string);
+ // Starting time
+ $querytimeBefore = array_sum(explode(' ', microtime()));
+
// Run SQL command
//* DEBUG: */ echo $sql_string."<br />\n";
$result = mysql_query($sql_string, $link)
//
// Debugging stuff...
//
- $fp = @fopen(PATH."inc/cache/mysql.log", 'a') or mxchange_die("Cannot write mysql.log!");
+ $fp = fopen(constant('PATH')."inc/cache/mysql.log", 'a') or mxchange_die("Cannot write mysql.log!");
if (!isset($OK)) {
// Write first entry
fwrite($fp, "Module=".$GLOBALS['module']."\n");
} // END - if
// Count DB hits
- if (getConfig('db_hits_run') == null) {
+ if (!isConfigEntrySet('db_hits_run')) {
// Count in dummy variable
setConfigEntry('db_hits_run', 1);
} else {
}
// SQL num rows
-function SQL_NUMROWS($result) {
+function SQL_NUMROWS ($result) {
// Is the result a valid resource?
if (is_resource($result)) {
// Get the count of rows from database
for ($idx = 0; $idx < ($max / 2); $idx++) {
// Remove entry
unset($row[$idx]);
- }
- }
+ } // END - for
+ } // END - if
// Return row
return $row;
$result = mysql_result($res, $row, $field);
return $result;
}
+
// SQL connect
function SQL_CONNECT ($host, $login, $password, $F, $L) {
$connect = mysql_connect($host, $login, $password) or addFatalMessage($F." (".$L."):".mysql_error());
return $connect;
}
+
// SQL select database
function SQL_SELECT_DB ($dbName, $link, $F, $L) {
// Is there still a valid link? If not, skip it.
return mysql_select_db($dbName, $link) or addFatalMessage($F." (".$L."):".mysql_error());
}
+
// SQL close link
function SQL_CLOSE (&$link, $F, $L) {
global $cacheInstance, $cacheArray;
}
// SQL string escaping
-function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) {
+function SQL_QUERY_ESC ($qstring, $data, $F, $L, $run=true, $strip=true) {
global $link;
// Link is there?
} else {
$eval .= ", ''";
}
- }
+ } // END - foreach
$eval .= ");";
//
// Debugging
//
- //* DEBUG: */ $fp = fopen(PATH."inc/cache/escape_debug.log", 'a') or mxchange_die("Cannot write debug.log!");
- //* DEBUG: */ fwrite($fp, $file."(".$line."): ".str_replace("\r", "", str_replace("\n", " ", $eval))."\n");
+ //* DEBUG: */ $fp = fopen(constant('PATH')."inc/cache/escape_debug.log", 'a') or mxchange_die("Cannot write debug.log!");
+ //* DEBUG: */ fwrite($fp, $F."(".$L."): ".str_replace("\r", "", str_replace("\n", " ", $eval))."\n");
//* DEBUG: */ fclose($fp);
// Run the code
// Was the eval() command fine?
if ($query == "failed") {
// Something went wrong?
- print "eval=".htmlentities($eval)."<pre>";
- debug_print_backtrace();
- die("</pre>");
+ debug_report_bug("eval={$eval}");
} // END - if
- if ($run) {
+ if ($run === true) {
// Run SQL query (default)
- return SQL_QUERY($query, $file, $line);
+ return SQL_QUERY($query, $F, $L);
} else {
// Return secured string
return $query;
} // END - if
if (!is_resource($link)) {
- // Fall-back to addslashes() when there is no link
- return addslashes($str);
- } // END - if
-
- if (function_exists('mysql_real_escape_string')) {
+ // Fall-back to smartAddSlashes() when there is no link
+ return smartAddSlashes($str);
+ } elseif (function_exists('mysql_real_escape_string')) {
// The new and improved version
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):str={$str}<br />\n";
return mysql_real_escape_string($str, $link);
// The obsolete function
return mysql_escape_string($str, $link);
} else {
- // If nothing else works
- return addslashes($str);
+ // If nothing else works, fall back to smartAddSlashes()
+ return smartAddSlashes($str);
}
}
// SELECT query string from table, columns and so on... ;-)
function SQL_RESULT_FROM_ARRAY ($table, $columns, $idRow, $id, $F, $L) {
// Is columns an array?
- if (!is_array($columns) {
+ if (!is_array($columns)) {
// No array
trigger_error(sprintf("columns is not array. %s!=array", gettype($columns)));
- }
+ } // END - if
// Prepare the SQL statement
$SQL = "SELECT `".implode("`, `", $columns)."` FROM `{!_MYSQL_PREFIX!}_%s` WHERE ``='%s' LIMIT 1";
$result = false;
// Determine index/fulltext/unique word
- $noIndex = ((eregi("INDEX", $sql) == false) && (eregi("FULLTEXT", $sql) == false) && (eregi("UNIQUE", $sql) == false);
+ // 12 3 3 2 2 3 3 2 2 3 3 21
+ $noIndex = ((eregi("INDEX", $sql) == false) && (eregi("FULLTEXT", $sql) == false) && (eregi("UNIQUE", $sql) == false));
// Shall we add/drop?
if (((eregi("ADD", $sql) > 0) || (eregi("DROP", $sql) > 0)) && ($noIndex)) {
array($tableName, $columnName), $F, $L);
// Do we have no entry on ADD or an entry on DROP?
+ // 123 4 4 3 3 4 4 32 23 4 4 3 3 4 4 321
if (((SQL_NUMROWS($result) == 0) && (eregi("ADD", $sql) > 0)) || ((SQL_NUMROWS($result) == 1) && (eregi("DROP", $sql) > 0))) {
// Do the query
$result = SQL_QUERY($sql, $F, $L, false);
// Return result
return $result;
}
+
//
?>