]> git.mxchange.org Git - mailer.git/blobdiff - inc/db/lib-mysqli.php
Disallow subtraction on unsigned columns:
[mailer.git] / inc / db / lib-mysqli.php
index 02d0c8e5da12fbe5aaf47debb4f22bc48ab8ef66..9a1be873010ff6d78a9cef318bfa8739c8d03437 100644 (file)
@@ -44,7 +44,7 @@ if (!defined('__SECURITY')) {
 function sqlQuery ($sqlString, $file, $line, $enableCodes = TRUE) {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$sqlString])) {
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called: ' . $sqlString);
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called: ' . $sqlString);
 
                // Trim SQL string
                $sqlStringModified = trim($sqlString);
@@ -69,7 +69,9 @@ function sqlQuery ($sqlString, $file, $line, $enableCodes = TRUE) {
                $sqlStringModified = str_replace(array(chr(9), PHP_EOL, chr(13)), array(' ', ' ', ' '), $sqlStringModified);
 
                // Compile config entries out
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlStringModified=' . $sqlStringModified . ',enableCodes=' . intval($enableCodes));
                $sqlStringModified = sqlPrepareQueryString($sqlStringModified, $enableCodes);
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sqlStringModified=' . $sqlStringModified . ',enableCodes=' . intval($enableCodes));
 
                // Cache it and remember as last SQL query
                $GLOBALS[__FUNCTION__][$sqlString] = $sqlStringModified;
@@ -93,7 +95,7 @@ function sqlQuery ($sqlString, $file, $line, $enableCodes = TRUE) {
        // Run SQL command
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . basename($file) . ',line=' . $line . ',sql=' . $GLOBALS['last_sql']);
        $result = mysqli_query(getSqlLink(), $GLOBALS['last_sql'])
-               or sqlError($file, $line, 'file='. basename($file) . ',line=' . $line . ':mysqli_error()=' . mysqli_error() . ',last_query=' . $GLOBALS['last_sql']);
+               or sqlError($file, $line, 'file='. basename($file) . ',line=' . $line . ':mysqli_error()=' . mysqli_error(getSqlLink()) . ',last_query=' . $GLOBALS['last_sql']);
        //* DEBUG: */ logDebugMessage($file, $line, 'sql=' . $GLOBALS['last_sql'] . ',affected=' . sqlAffectedRows() . ',numRows='.(isValidSqlLink($result) ? sqlNumRows($result) : gettype($result)));
 
        // Calculate query time
@@ -197,7 +199,7 @@ function sqlResult ($resource, $row, $field = '0') {
 // SQL connect
 function sqlConnectToDatabase ($host, $login, $password, $file, $line) {
        // Try to connect
-       $linkResource = mysqli_connect($host, $login, $password) or sqlError($file, $line,  mysqli_error());
+       $linkResource = mysqli_connect($host, $login, $password) or sqlError($file, $line,  mysqli_error(getSqlLink()));
 
        // Set the link resource
        if ($linkResource instanceof mysqli) {
@@ -216,6 +218,9 @@ function sqlConnectToDatabase ($host, $login, $password, $file, $line) {
        `character_set_connection`='utf8',
        `character_set_database`='utf8',
        `character_set_server`='utf8'", $file . ':' . __FUNCTION__, $line . ':' . __LINE__);
+
+               // Disallow subtraction for unsigned columns
+               sqlQuery("SET `sql_mode`='NO_UNSIGNED_SUBTRACTION'", $file . ':' . __FUNCTION__, $line . ':' . __LINE__);
        } // END - if
 
        // Any errors encountered?
@@ -236,7 +241,7 @@ function sqlSelectDatabase ($dbName, $file, $line) {
 
        // Return the result
        //* DEBUG: */ logDebugMessage($file . ':' . __FUNCTION__, $line . ':' . __LINE__, 'Selecting database ' . $dbName);
-       return mysqli_select_db(getSqlLink(), $dbName) or sqlError($file, $line,  mysqli_error());
+       return mysqli_select_db(getSqlLink(), $dbName) or sqlError($file, $line,  mysqli_error(getSqlLink()));
 }
 
 // SQL close link
@@ -249,7 +254,7 @@ function sqlCloseLink ($file, $line) {
        } // END - if
 
        // Close database link and forget the link
-       $close = mysqli_close(getSqlLink()) or sqlError($file . ':' . __FUNCTION__, $line . ':' . __LINE__, mysqli_error());
+       $close = mysqli_close(getSqlLink()) or sqlError($file . ':' . __FUNCTION__, $line . ':' . __LINE__, mysqli_error(getSqlLink()));
 
        // Close link in this layer
        unsetSqlLinkUp(__FUNCTION__, __LINE__);
@@ -341,7 +346,7 @@ function sqlEscapeString ($str, $secureString = TRUE, $strip = TRUE) {
 // Log SQL errors to debug.log in installation phase or call reportBug()
 function sqlError ($file, $line, $message) {
        // Remember plain error in last_sql_error
-       $GLOBALS['last_sql_error'] = mysqli_error();
+       $GLOBALS['last_sql_error'] = mysqli_error(getSqlLink());
 
        // Is login set?
        if (!empty($GLOBALS['mysql']['login'])) {