Skip to content

Commit

Permalink
Merge pull request #752 from nicolas-grekas/fix-error-handling
Browse files Browse the repository at this point in the history
Fix error handling in mysqli driver
  • Loading branch information
deeky666 committed Dec 31, 2014
2 parents aea8383 + 6285c67 commit 6d766f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function fetchColumn($columnIndex = 0)
return false;
}

return $row[$columnIndex];
return isset($row[$columnIndex]) ? $row[$columnIndex] : null;
}

/**
Expand Down

0 comments on commit 6d766f6

Please sign in to comment.