summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/mysqli/mysqli_driver.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-01-11 11:09:52 +0100
committerAndrey Andreev <narf@devilix.net>2016-01-11 11:09:52 +0100
commit38b08116c61c0a68e6d350c986f75589220692ed (patch)
treefa8a9b5a0f0be955d42110b67037d1ff46e54604 /system/database/drivers/mysqli/mysqli_driver.php
parent34251bfec2627fb0526d5f99f3a13a3d8a4506d8 (diff)
parentfd5fe1a64c03ae7204a7e72d936215f7a61d8c30 (diff)
Merge branch '3.0-stable' into develop
Resolved conflicts: system/database/drivers/mysql/mysql_driver.php system/database/drivers/mysqli/mysqli_driver.php
Diffstat (limited to 'system/database/drivers/mysqli/mysqli_driver.php')
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php77
1 files changed, 59 insertions, 18 deletions
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 847544780..cec1f8692 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -84,7 +84,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* @var bool
*/
- public $stricton = FALSE;
+ public $stricton;
// --------------------------------------------------------------------
@@ -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,30 @@ 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)
+ if (isset($this->stricton))
{
- $mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode="STRICT_ALL_TABLES"');
+ if ($this->stricton)
+ {
+ $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
+ }
+ else
+ {
+ $this->_mysqli->options(MYSQLI_INIT_COMMAND,
+ 'SET SESSION sql_mode =
+ REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
+ @@sql_mode,
+ "STRICT_ALL_TABLES,", ""),
+ ",STRICT_ALL_TABLES", ""),
+ "STRICT_ALL_TABLES", ""),
+ "STRICT_TRANS_TABLES,", ""),
+ ",STRICT_TRANS_TABLES", ""),
+ "STRICT_TRANS_TABLES", "")'
+ );
+ }
}
if (is_array($this->encrypt))
@@ -142,13 +170,26 @@ class CI_DB_mysqli_driver extends CI_DB {
if ( ! empty($ssl))
{
- if ( ! empty($this->encrypt['ssl_verify']) && defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT'))
+ if (isset($this->encrypt['ssl_verify']))
{
- $mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
+ if ($this->encrypt['ssl_verify'])
+ {
+ defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
+ }
+ // Apparently (when it exists), setting MYSQLI_OPT_SSL_VERIFY_SERVER_CERT
+ // to FALSE didn't do anything, so PHP 5.6.16 introduced yet another
+ // constant ...
+ //
+ // https://secure.php.net/ChangeLog-5.php#5.6.16
+ // https://bugs.php.net/bug.php?id=68344
+ elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT'))
+ {
+ $this->_mysqli->options(MYSQLI_CLIENT_SSL_DONT_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,29 +199,29 @@ 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;
}
- if ( ! $mysqli->set_charset($this->char_set))
+ if ( ! $this->_mysqli->set_charset($this->char_set))
{
log_message('error', "Database: Unable to set the configured connection charset ('{$this->char_set}').");
- $mysqli->close();
+ $this->_mysqli->close();
return ($this->db->db_debug) ? $this->display_error('db_unable_to_set_charset', $this->char_set) : FALSE;
}
- return $mysqli;
+ return $this->_mysqli;
}
return FALSE;
@@ -451,11 +492,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()
);
}