PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; try { $pdo = new PDO($dsn, $user, $pass, $options); } catch (PDOException $e) { // In a real application, you would log this error and show a generic error page. // For development, it's okay to die and show the error. throw new PDOException($e->getMessage(), (int)$e->getCode()); } return $pdo; }