1$host = "localhost";//Ip of database, in this case my host machine
2$user = "root"; //Username to use
3$pass = "qwerty";//Password for that user
4$dbname = "DB";//Name of the database
5
6try {
7 $connection = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
8 $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
9
10}catch(PDOException $e)
11{
12 echo $e->getMessage();
13}
1$conn=new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
2 // If this is your connection then you have to assign null
3 // to your connection variable as follows:
4$conn=null;
5 // By this way you can close connection in PDO.
6