Evening,
I am currently handling PDO exceptions like this:
try{
$db = Db::connect();
$query = $db->prepare( "SELECT * FROM table;" );
$query->execute();
}
catch( PDOException $e ) { error( 'MySQL error: ' . $e->getMessage(), __FILE__, __LINE__ ); }
My handling each time is exactly the same. So I am wondering if there is a way I can set up that when there is a PDO exception that it automatically runs:
catch( PDOException $e ) { error( 'MySQL error: ' . $e->getMessage(), __FILE__, __LINE__ ); }
Take a look at the Documentation of PDO
You can change the error handling to PDO::ERRMODE_SILENT or PDO::ERRMODE_WARNING
Or use set_exception_handler and define a handler for all your exceptions.