Commit 57186d5c authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #525 from marcini/master

Added flags support for mysqli::real_connect in Mysqli driver.
parents 8f2fbf11 c55e891a
...@@ -29,6 +29,11 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection; ...@@ -29,6 +29,11 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
*/ */
class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection
{ {
/**
* Name of the option to set connection flags
*/
const OPTION_FLAGS = 'flags';
/** /**
* @var \mysqli * @var \mysqli
*/ */
...@@ -47,6 +52,8 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -47,6 +52,8 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
$port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port'); $port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port');
$socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket'); $socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket');
$flags = isset($driverOptions[static::OPTION_FLAGS]) ? $driverOptions[static::OPTION_FLAGS] : null;
$this->_conn = mysqli_init(); $this->_conn = mysqli_init();
$this->setDriverOptions($driverOptions); $this->setDriverOptions($driverOptions);
...@@ -54,7 +61,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -54,7 +61,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
$previousHandler = set_error_handler(function () { $previousHandler = set_error_handler(function () {
}); });
if ( ! $this->_conn->real_connect($params['host'], $username, $password, $params['dbname'], $port, $socket)) { if ( ! $this->_conn->real_connect($params['host'], $username, $password, $params['dbname'], $port, $socket, $flags)) {
set_error_handler($previousHandler); set_error_handler($previousHandler);
$sqlState = 'HY000'; $sqlState = 'HY000';
...@@ -216,6 +223,10 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -216,6 +223,10 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
foreach ($driverOptions as $option => $value) { foreach ($driverOptions as $option => $value) {
if ($option === static::OPTION_FLAGS) {
continue;
}
if (!in_array($option, $supportedDriverOptions, true)) { if (!in_array($option, $supportedDriverOptions, true)) {
throw new MysqliException( throw new MysqliException(
sprintf($exceptionMsg, 'Unsupported', $option, $value) sprintf($exceptionMsg, 'Unsupported', $option, $value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment