Reputation: 211
i have a few question on php db connection and hoping someone can answer them all, when i create a db connection using pdo, like below
<?php
/* Connect to an ODBC database using driver invocation */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
Upvotes: 1
Views: 412
Reputation: 61
I found this in the php manual. Hope it helps.
To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted--you do this by assigning NULL to the variable that holds the object. If you don't do this explicitly, PHP will automatically close the connection when your script ends.
Upvotes: 1
Reputation: 255155
Upvotes: 1