]> git.mxchange.org Git - mailer.git/blobdiff - inc/db/lib-mysql3.php
Updated copyright notice as there are changes in this year
[mailer.git] / inc / db / lib-mysql3.php
index e577551244475eff1a4dda43238c663e3089198a..e20b271d441016ce53c29f553404890a75f197cb 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -75,7 +75,10 @@ function SQL_QUERY ($sqlString, $F, $L, $enableCodes = TRUE) {
                $GLOBALS[__FUNCTION__][$sqlString] = $sqlStringModified;
                $GLOBALS['last_sql']               = $sqlStringModified;
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Stored cache: ' . $sqlStringModified);
-       }  else {
+       } elseif (!SQL_IS_LINK_UP()) {
+               // Link went down while using cached SQL
+               reportBug(__FUNCTION__, __LINE__, 'Link went down while using cached SQL: sqlString=' . $sqlString . ',F=' . basename($F) . ',L=' . $L . ',enableCodes=' . intval($enableCodes));
+       } else {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache used: ' . $sqlString);
 
                // Use cache (to save a lot function calls
@@ -156,7 +159,7 @@ function SQL_NUMROWS ($resource) {
 }
 
 // SQL affected rows
-function SQL_AFFECTEDROWS() {
+function SQL_AFFECTEDROWS () {
        // Valid link resource?
        if (!SQL_IS_LINK_UP()) return FALSE;
 
@@ -169,7 +172,7 @@ function SQL_AFFECTEDROWS() {
 
 // SQL fetch row
 function SQL_FETCHROW ($resource) {
-       // Is a result resource set?
+       // Is $resource valid?
        if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) return FALSE;
 
        // Fetch the data and return it
@@ -178,10 +181,10 @@ function SQL_FETCHROW ($resource) {
 
 // SQL fetch array
 function SQL_FETCHARRAY ($resource) {
-       // Is a result resource set?
+       // Is $resource valid?
        if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) return FALSE;
 
-       // Load row from database
+       // Load row as array from database
        $row = mysql_fetch_assoc($resource);
 
        // Return only arrays here
@@ -219,10 +222,19 @@ function SQL_CONNECT ($host, $login, $password, $F, $L) {
                 * SQL_IS_LINK_UP() will only return 'true' if there is really a
                 * working database link.
                 */
-               SQL_SET_LINK($linkResource);
+               SQL_SET_LINK(__FUNCTION__, __LINE__, $linkResource);
+
+               // Init charsets (UTF-8 is default now)
+               SQL_QUERY("SET
+       `character_set_results`='utf8',
+       `character_set_client`='utf8',
+       `character_set_connection`='utf8',
+       `character_set_database`='utf8',
+       `character_set_server`='utf8'", __FUNCTION__, __LINE__);
        } // END - if
 
        // Return the resource
+       //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'linkResource[]=' . gettype($linkResource));
        return $linkResource;
 }
 
@@ -232,23 +244,27 @@ function SQL_SELECT_DB ($dbName, $F, $L) {
        if (!SQL_IS_LINK_UP()) return FALSE;
 
        // Return the result
+       //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'Selecting database ' . $dbName);
        return mysql_select_db($dbName, SQL_GET_LINK()) or SQL_ERROR($F, $L,  mysql_error());
 }
 
 // SQL close link
 function SQL_CLOSE ($F, $L) {
+       // Is the link up?
        if (!SQL_IS_LINK_UP()) {
                // Skip double close
+               //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'Called but no link is open.');
                return FALSE;
        } // END - if
 
        // Close database link and forget the link
-       $close = mysql_close(SQL_GET_LINK()) or SQL_ERROR($F, $L, mysql_error());
+       $close = mysql_close(SQL_GET_LINK()) or SQL_ERROR($F . ':' . __FUNCTION__, $L . ':' . __LINE__, mysql_error());
 
-       // Close link
-       SQL_SET_LINK(NULL);
+       // Close link in this layer
+       unsetSqlLinkUp(__FUNCTION__, __LINE__);
 
        // Return the result
+       //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'close[' . gettype($close) . ']=' . intval($close));
        return $close;
 }
 
@@ -266,10 +282,10 @@ function SQL_FREERESULT ($resource) {
        return $res;
 }
 
-// Get id from last INSERT command
-function SQL_INSERTID () {
+// Get id from last INSERT command and secure id
+function SQL_INSERT_ID () {
        if (!SQL_IS_LINK_UP()) return FALSE;
-       return mysql_insert_id();
+       return bigintval(mysql_insert_id());
 }
 
 // Escape a string for the database