From 6285c67ad0fc1c78e9978f4fb665ff257ec88d98 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 19 Dec 2014 11:16:59 +0100 Subject: [PATCH] Fix error handling in mysqli driver --- .../DBAL/Driver/Mysqli/MysqliConnection.php | 14 ++++---------- .../DBAL/Driver/Mysqli/MysqliStatement.php | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 83935a37bc..ae3502c168 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -65,21 +65,15 @@ public function __construct(array $params, $username, $password, array $driverOp $this->setDriverOptions($driverOptions); - $previousHandler = set_error_handler(function () { - }); + set_error_handler(function () {}); if ( ! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { - set_error_handler($previousHandler); + restore_error_handler(); - $sqlState = 'HY000'; - if (@$this->_conn->sqlstate) { - $sqlState = $this->_conn->sqlstate; - } - - throw new MysqliException($this->_conn->connect_error, $sqlState, $this->_conn->connect_errno); + throw new MysqliException($this->_conn->connect_error, @$this->_conn->sqlstate ?: 'HY000', $this->_conn->connect_errno); } - set_error_handler($previousHandler); + restore_error_handler(); if (isset($params['charset'])) { $this->_conn->set_charset($params['charset']); diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 17264604a9..edc02dff55 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -300,7 +300,7 @@ public function fetchColumn($columnIndex = 0) return false; } - return $row[$columnIndex]; + return isset($row[$columnIndex]) ? $row[$columnIndex] : null; } /**