Improved error handling of the PDO database