]> git.mxchange.org Git - mailer.git/blobdiff - inc/db/lib-mysql3.php
Fixes/rewrites for 'dublicate entry' bug
[mailer.git] / inc / db / lib-mysql3.php
index 4492111863fba94c9f3d3f29edc9763e75de89ff..b32507823876eb3fbfc042c2857fc65e6e1a18dc 100644 (file)
@@ -39,8 +39,6 @@ if (!defined('__SECURITY')) {
 
 // SQL queries
 function SQL_QUERY ($sql_string, $F, $L) {
-       global $OK;
-
        // Link is up?
        if (!SQL_IS_LINK_UP()) return false;
 
@@ -56,7 +54,7 @@ function SQL_QUERY ($sql_string, $F, $L) {
        // 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);
 
@@ -74,16 +72,15 @@ Query string:<br />
 
        // 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);
@@ -182,7 +179,7 @@ function SQL_RESULT ($res, $row, $field) {
 // 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);
@@ -194,7 +191,7 @@ function SQL_SELECT_DB ($dbName, $F, $L) {
        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
@@ -206,16 +203,16 @@ function SQL_CLOSE ($F, $L) {
 
        // 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);
@@ -290,7 +287,7 @@ function SQL_INSERTID () {
 }
 
 // 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
@@ -322,10 +319,10 @@ function SQL_RESULT_FROM_ARRAY ($table, $columns, $idRow, $id, $F, $L) {
        } // 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,
@@ -387,8 +384,14 @@ function SQL_GET_LINK () {
 
 // 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