summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php37
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 25 insertions, 13 deletions
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 827470078..693a96bab 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -98,6 +98,17 @@ class CI_DB_mysqli_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * MySQLi object
+ *
+ * Has to be preserved without being assigned to $conn_id.
+ *
+ * @var MySQLi
+ */
+ protected $_mysqli;
+
+ // --------------------------------------------------------------------
+
+ /**
* Database connection
*
* @param bool $persistent
@@ -122,13 +133,13 @@ class CI_DB_mysqli_driver extends CI_DB {
}
$client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0;
- $mysqli = mysqli_init();
+ $this->_mysqli = mysqli_init();
- $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
+ $this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
if ($this->stricton)
{
- $mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode="STRICT_ALL_TABLES"');
+ $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode="STRICT_ALL_TABLES"');
}
if (is_array($this->encrypt))
@@ -144,11 +155,11 @@ class CI_DB_mysqli_driver extends CI_DB {
{
if ( ! empty($this->encrypt['ssl_verify']) && defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT'))
{
- $mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
+ $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
}
$client_flags |= MYSQLI_CLIENT_SSL;
- $mysqli->ssl_set(
+ $this->_mysqli->ssl_set(
isset($ssl['key']) ? $ssl['key'] : NULL,
isset($ssl['cert']) ? $ssl['cert'] : NULL,
isset($ssl['ca']) ? $ssl['ca'] : NULL,
@@ -158,22 +169,22 @@ class CI_DB_mysqli_driver extends CI_DB {
}
}
- if ($mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags))
+ if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags))
{
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
if (
($client_flags & MYSQLI_CLIENT_SSL)
- && version_compare($mysqli->client_info, '5.7.3', '<=')
- && empty($mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)
+ && version_compare($this->_mysqli->client_info, '5.7.3', '<=')
+ && empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)
)
{
- $mysqli->close();
+ $this->_mysqli->close();
$message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
log_message('error', $message);
return ($this->db->db_debug) ? $this->db->display_error($message, '', TRUE) : FALSE;
}
- return $mysqli;
+ return $this->_mysqli;
}
return FALSE;
@@ -457,11 +468,11 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function error()
{
- if ( ! empty($this->conn_id->connect_errno))
+ if ( ! empty($this->_mysqli->connect_errno))
{
return array(
- 'code' => $this->conn_id->connect_errno,
- 'message' => is_php('5.2.9') ? $this->conn_id->connect_error : mysqli_connect_error()
+ 'code' => $this->_mysqli->connect_errno,
+ 'message' => is_php('5.2.9') ? $this->_mysqli->connect_error : mysqli_connect_error()
);
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 3b832b3a9..3f2204847 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -28,6 +28,7 @@ Bug fixes for 3.0.4
- Fixed a bug where :doc:`Session Library <libraries/sessions>` didn't have proper error handling on PHP 5 (due to a PHP bug).
- Fixed a bug (#4312) - :doc:`Form Validation Library <libraries/form_validation>` didn't provide error feedback for failed validation on empty requests.
- Fixed a bug where :doc:`Database <database/index>` method `version()` returned banner text instead of only the version number with the 'oci8' and 'pdo/oci' drivers.
+- Fixed a bug (#4331) - :doc:`Database <database/index>` method ``error()`` didn't really work for connection errors with the 'mysqli' driver.
Version 3.0.3
=============