Functions imported, some dev-scripts added
[mailer.git] / inc / db / lib-mysql3.php
index b1850f4efa553eb7983d1ed102eefd3cd7a813ed..f90a8f6f9ab8b009b1f8a885b86822a416349cb5 100644 (file)
@@ -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)));
 
        // 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);
 
        // 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)
        // Run SQL command
        //* DEBUG: */ echo $sql_string."<br />\n";
        $result = mysql_query($sql_string, $link)
@@ -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]);
                        for ($idx = 0; $idx < ($max / 2); $idx++) {
                                // Remove entry
                                unset($row[$idx]);
-                       }
-               }
+                       } // END - for
+               } // END - if
 
                // Return row
                return $row;
 
                // Return row
                return $row;
@@ -180,11 +180,13 @@ function SQL_RESULT ($res, $row, $field) {
        $result = mysql_result($res, $row, $field);
        return $result;
 }
        $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 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.
 // 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());
 }
 
        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 close link
 function SQL_CLOSE (&$link, $F, $L) {
        global $cacheInstance, $cacheArray;
@@ -251,7 +254,7 @@ function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) {
                } else {
                        $eval .= ", ''";
                }
                } else {
                        $eval .= ", ''";
                }
-       }
+       } // END - foreach
        $eval .= ");";
        //
        // Debugging
        $eval .= ");";
        //
        // Debugging
@@ -266,16 +269,10 @@ function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) {
        // Was the eval() command fine?
        if ($query == "failed") {
                // Something went wrong?
        // Was the eval() command fine?
        if ($query == "failed") {
                // Something went wrong?
-               printf("eval=%s\n<pre>%s</pre>",
-                       htmlentities($eval),
-                       debug_get_printable_backtrace()
-               );
-
-               // Abort further code executions
-               exit;
+               debug_report_bug("eval={$eval}");
        } // END - if
 
        } // END - if
 
-       if ($run) {
+       if ($run === true) {
                // Run SQL query (default)
                return SQL_QUERY($query, $file, $line);
        } else {
                // Run SQL query (default)
                return SQL_QUERY($query, $file, $line);
        } else {
@@ -302,11 +299,9 @@ function SQL_ESCAPE ($str, $secureString=true,$strip=true) {
        } // END - if
 
        if (!is_resource($link)) {
        } // 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 new and improved version
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):str={$str}<br />\n";
                return mysql_real_escape_string($str, $link);
@@ -314,8 +309,8 @@ function SQL_ESCAPE ($str, $secureString=true,$strip=true) {
                // The obsolete function
                return mysql_escape_string($str, $link);
        } else {
                // 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);
        }
 }
 
        }
 }
 
@@ -345,7 +340,8 @@ function SQL_ALTER_TABLE ($sql, $F, $L) {
        $result = false;
 
        // Determine index/fulltext/unique word
        $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)) {
 
        // Shall we add/drop?
        if (((eregi("ADD", $sql) > 0) || (eregi("DROP", $sql) > 0)) && ($noIndex)) {
@@ -374,5 +370,6 @@ function SQL_ALTER_TABLE ($sql, $F, $L) {
        // Return result
        return $result;
 }
        // Return result
        return $result;
 }
+
 //
 ?>
 //
 ?>