1<?php
2$servername = "localhost";
3$username = "username";
4$password = "password";
5
6try {
7 $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
8 // set the PDO error mode to exception
9 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
10 echo "Connected successfully";
11 }
12catch(PDOException $e)
13 {
14 echo "Connection failed: " . $e->getMessage();
15 }
16?>
1<?php
2
3 $pdo = new PDO('mysql:host=localhost;
4 dbname=the_name_of_your_databe,
5 'username',
6 'password'');
7# by default your username is root
8# if you don't have a password don't fill in it
9
10#(optional) :
11 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
12 $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
13
14?>
1$hostName = "localhost";
2$dbName = "test";
3$userName = "test";
4$password = "test1";
5try {
6 $pdo = new PDO("mysql:host=$hostName;dbname=$dbName",$userName,$password);
7 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
8 echo "Connected successfully";
9 }
10 catch(PDOException $e)
11 {
12 echo "Connection failed: " . $e->getMessage();
13 }
14