We can connect database with PDO by
try
{
$con = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
print 'Connection Successful';
}
catch(PDOException $e)
{
print $e->getMessage();
}
/* I used try catch for Exception Handling */
We can close the database connection of PDO by simply
$con = null;
By the simple assignment of null value to database connection object we can close connection.
try
{
$con = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
print 'Connection Successful';
}
catch(PDOException $e)
{
print $e->getMessage();
}
/* I used try catch for Exception Handling */
We can close the database connection of PDO by simply
$con = null;
By the simple assignment of null value to database connection object we can close connection.

0 comments:
Post a Comment