The pdo connection does not close once the instructions have been executed

advertisements

Using PHP 5.5, I've noticed that I cannot close PDO connections after I've already executed statements using a connection.

For instance:

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$dbh = null;

Closes the connection just fine. But I can't get the following connection to close here:

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$stmt = $dbh->prepare("select * from someTable where 1<>0");
$stmt->execute();
$dbh = null;


You can see a related note about this on the PHP docs here http://php.net/manual/en/pdo.connections.php#114822. In short, you need to set the statement and the connection to null.

$stmt = null;
$dbh = null;