I always want PDO to throw exceptions if an error occurs, as I always use PDO like so:
try {
$dbh = new PDO("mysql:host=$kdbhost;dbname=$kdbname",$kdbuser,$kdbpw);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// some queries
}
catch (PDOException $e) {
error_log('PDO Exception: '.$e->getMessage());
die('PDO says no.');
}
It would be nice if there was a config file I could edit to make it so PDO throws exceptions by default - is this possible?
The reason I want this is so I don't have to write this line every time:
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Update - I have since created a library which handles database access for me (including setting PDO to throw exceptions).