Skip to content

Commit

Permalink
MySQLi Improvements (#21)
Browse files Browse the repository at this point in the history
* MySQLi Improvements

* Add close to failing raw
  • Loading branch information
bajb authored and TomK committed Jun 15, 2018
1 parent 6865f2a commit ace9475
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Ql/MySQLiConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ public function isConnected()

protected function _disconnect()
{
if($this->_connection)
{
$this->_connection->close();
}
$this->_connection = null;
}

public function _connect()
{
$options = array_replace(
$this->_defaultOptions(),
ValueAs::arr($this->_config()->getItem('options'))
);
$options = array_replace($this->_defaultOptions(), ValueAs::arr($this->_config()->getItem('options')));

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$this->_connection = null;
$connection = new \mysqli();
$connection->init();

foreach($options as $key => $value)
{
Expand All @@ -51,6 +54,12 @@ public function _connect()
$this->_config()->getItem('port', 3306)
);

$charSet = $this->_config()->getItem('charset');
if($charSet)
{
$connection->set_charset($charSet);
}

$this->_connection = $connection;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Ql/Mocks/FailingPrepareRawConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public function ping()
return true;
}

public function close()
{
return true;
}

public function prepare()
{
$exception = new ConnectionException(
Expand Down

0 comments on commit ace9475

Please sign in to comment.