X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fdb%2Flib-mysql3.php;h=50b7189f8358b768cbee03da7fc8115b129c3c5e;hb=d52156d35605388b7554c31d08bc29f0bb167079;hp=61d9be17fa1305e720669059823f380a1851389e;hpb=a954ccdf4aba81ec0e75a1836aa4bc14cb245aba;p=mailer.git diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 61d9be17fa..50b7189f83 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -47,12 +47,12 @@ function SQL_QUERY ($sql_string, $F, $L) { // 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."
\n"; $result = mysql_query($sql_string, $link) @@ -79,7 +79,7 @@ Query string:
// // 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"); @@ -164,8 +164,8 @@ function SQL_FETCHARRAY($res, $nr=0, $remove_numerical=true) { for ($idx = 0; $idx < ($max / 2); $idx++) { // Remove entry unset($row[$idx]); - } - } + } // END - for + } // END - if // Return row return $row; @@ -180,11 +180,13 @@ function SQL_RESULT ($res, $row, $field) { $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. @@ -192,6 +194,7 @@ function SQL_SELECT_DB ($dbName, $link, $F, $L) { return mysql_select_db($dbName, $link) or addFatalMessage($F." (".$L."):".mysql_error()); } + // SQL close link function SQL_CLOSE (&$link, $F, $L) { global $cacheInstance, $cacheArray; @@ -229,7 +232,7 @@ function SQL_FREERESULT ($result) { } // 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? @@ -251,13 +254,13 @@ function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) { } 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 @@ -266,18 +269,12 @@ function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) { // Was the eval() command fine? if ($query == "failed") { // Something went wrong? - printf("eval=%s\n
%s
", - htmlentities($eval), - debug_get_printable_backtrace() - ); - - // Abort further code executions - exit; + 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; @@ -302,11 +299,9 @@ function SQL_ESCAPE ($str, $secureString=true,$strip=true) { } // 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__."(".__LINE__."):str={$str}
\n"; return mysql_real_escape_string($str, $link); @@ -314,18 +309,18 @@ function SQL_ESCAPE ($str, $secureString=true,$strip=true) { // 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"; @@ -345,7 +340,8 @@ function SQL_ALTER_TABLE ($sql, $F, $L) { $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)) { @@ -361,6 +357,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L) { 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); @@ -373,5 +370,6 @@ function SQL_ALTER_TABLE ($sql, $F, $L) { // Return result return $result; } + // ?>