Set PDO to throw exceptions by default [duplicate]

You can add the setAttribute function to the constructor:

$pdo = new PDO('mysql:host=localhost;dbname=someDatabase', 'username', 'password', array(
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));

But I cannot find a method to add it to the php.ini file or some other config file.

Leave a Comment