* -------------------------------------------------------------------- *
* Kurzbeschreibung : Datenbankschicht fuer MySQL 3/4/5 Server (MySQLi)*
* -------------------------------------------------------------------- *
- * $Revision:: $ *
- * $Date:: $ *
- * $Tag:: 0.2.1-FINAL $ *
- * $Author:: $ *
- * -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009 - 2013 by Mailer Developer Team *
+ * Copyright (c) 2009 - 2016 by Mailer Developer Team *
* For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
$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;
// 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 logSqlError($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
// 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 logSqlError($file, $line, mysqli_error(getSqlLink()));
// Set the link resource
if ($linkResource instanceof mysqli) {
`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?
// 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 logSqlError($file, $line, mysqli_error(getSqlLink()));
}
// SQL close link
} // 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 logSqlError($file . ':' . __FUNCTION__, $line . ':' . __LINE__, mysqli_error(getSqlLink()));
// Close link in this layer
unsetSqlLinkUp(__FUNCTION__, __LINE__);
// Get id from last INSERT command and secure id
function getSqlInsertId () {
if (!isSqlLinkUp()) return FALSE;
- return bigintval(mysqli_insert_id());
+ return bigintval(mysqli_insert_id(getSqlLink()));
}
// Escape a string for the database
return $GLOBALS['sql_escapes']['' . $str . ''];
}
-// Log SQL errors to debug.log in installation phase or call reportBug()
-function sqlError ($file, $line, $message) {
+// Set SQL error in global array
+function setSqlError ($file, $line, $message) {
// Remember plain error in last_sql_error
- $GLOBALS['last_sql_error'] = mysqli_error();
-
- // Is login set?
- if (!empty($GLOBALS['mysql']['login'])) {
- // Secure login name in message
- $message = str_replace($GLOBALS['mysql']['login'], '***', $message);
- } // END - if
-
- // Is database password set?
- if (!empty($GLOBALS['mysql']['password'])) {
- // Secure password in message
- $message = str_replace($GLOBALS['mysql']['password'], '***', $message);
- } // END - if
-
- // Is database name set?
- if (!empty($GLOBALS['mysql']['dbase'])) {
- // Secure database name in message
- $message = str_replace($GLOBALS['mysql']['dbase'], '***', $message);
- } // END - if
-
- // Is there installation phase?
- if (isInstaller()) {
- /*
- * In installation phase, we don't want SQL errors abort e.g. connection
- * tests, so just log it away.
- */
- logDebugMessage($file, $line, $message);
- } else {
- // Regular mode, then call reportBug()
- reportBug($file, $line, $message);
- }
+ $GLOBALS['last_sql_error'] = mysqli_error(getSqlLink());
}
// Checks whether given link is a valid SQL link