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}1public static function connexionBDD()
2    {
3        $base = null;
4
5        try {
6            $base = new PDO('mysql:host=' . MYSQL_HOSTNAME . '; dbname=' . MYSQL_DATABASE . '', MYSQL_USERNAME, MYSQL_PASSWORD);
7        } catch (exception $e) {
8            die('Erreur ' . $e->getMessage());
9        }
10
11        return $base;
12    }