DSN and connection options

The DSN (Data Source Name) is the string that tells PDO the driver, host, database and character set. The constructor options set the behavior: ERRMODE_EXCEPTION makes it throw exceptions on error, and FETCH_ASSOC sets the default fetch mode.

Example

$pdo = new PDO('mysql:host=localhost;dbname=app;charset=utf8mb4', $u, $p, [
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

Related concepts

The whole glossary