PDO::__construct — Create a PDO instance representing a database connection (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
PDO::__construct ( string $dsn [, string $username [, string $password [, array $driver_options ]]] )
Creates a database connection PDO instance that represents the connection to the requested database.
dsn : Data source name, or DSN, contains information requesting a connection to the database.
username : Username in DSN string. For some PDO drivers, this parameter is optional.
password : Password in DSN string. For some PDO drivers, this parameter is optional.
driver_options : A key => value array of connection options for a specific driver.
If the attempt to connect to the requested database fails, PDO::__construct() throws a PDOException.
<?php/* Create a PDO instance by calling the driver */$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();}?>