Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/core/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* @var string
*
*/
const CI_VERSION = '3.4.8';
const CI_VERSION = '3.4.9';

/*
* ------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion system/database/drivers/mysqli/mysqli_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function db_connect($persistent = FALSE)
*/
public function reconnect()
{
if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE)
if ($this->conn_id !== FALSE && $this->conn_id->query('DO 1') === FALSE)
{
$this->conn_id = FALSE;
}
Expand Down
44 changes: 44 additions & 0 deletions tests/codeigniter/database/Mysqli_reconnect_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

class Mysqli_reconnect_test extends CI_TestCase {

public function test_reconnect_detects_dropped_connection()
{
if (DB_DRIVER !== 'mysqli')
{
return $this->markTestSkipped('Requires the mysqli driver.');
}

$db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
$db->initialize();

$deprecations = array();
set_error_handler(function ($severity, $message) use (&$deprecations) {
$severity === E_DEPRECATED && $deprecations[] = $message;
return TRUE;
});

$db->reconnect();
$alive_after_live_check = ($db->conn_id !== FALSE);

$config = Mock_Database_DB::config(DB_DRIVER);
$config = $config[DB_DRIVER];
$admin = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database']);
$admin->query('KILL '.$db->conn_id->thread_id);
$admin->close();
usleep(200000);

$db->reconnect();
$dropped_after_dead_check = ($db->conn_id === FALSE);

$query = $db->query('SELECT 1 AS one');

restore_error_handler();

$this->assertSame(array(), $deprecations);
$this->assertTrue($alive_after_live_check);
$this->assertTrue($dropped_after_dead_check);
$this->assertEquals(1, $query->row()->one);
}

}