Easy Tutorial
❮ Func Date Gmmktime Php Pdo ❯

PDO::__construct

PHP PDO Reference Manual

PDO::__construct — Creates a PDO instance representing a connection to a database (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)


Description

Syntax

PDO::__construct ( string $dsn [, string $username [, string $password [, array $driver_options ]]] )

Creates a PDO instance representing a connection to the requested database.

Parameter Description


Return Value


Errors/Exceptions

If the attempt to connect to the requested database fails, PDO::__construct() throws a PDOException.


Examples

Creating a PDO Instance by Calling the Driver

<?php
/* Creating 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();
}

?>

PHP PDO Reference Manual

❮ Func Date Gmmktime Php Pdo ❯