In this PHP documentation it gives the following example of how to close a connection:
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
// use the connection here
// and now we're done; close it
$dbh = null;
But what if I'm using it in a function where $dbh
has only local scope, do I have to set it to null, or will the connection close when the function returns?
In my below example, is the connection closed?
public function doDBWork(){
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
// use the connection here
return true;
}