PHP Developers: MySQLi & PDO forcing errors helpful for debugging queries when accessing private or protected isolated classes

Sometimes you don’t have much control over other people’s code but your code must interact with it.  That’s one of the issues you will encounter when you work in a collaborative coding environment and you’re all developing code the proper way — there’s encapsulation so you know your code is isolated to only what you need to affect and others’ code stays within their boundaries.  You may find that you need more verbosity and details in the errors generated by other classes or libraries, perhaps you need to check the type of MySQL/SQL query errors that are being generated.

It may seem a little old school, this method has been around in PHP for 8 years, but it’s still useful today. Overriding the error handling will help you debug faster and that’s a good thing when you’re in the development stage. This is a handy way to set the error reporting and throw database errors to your PHP error handler instead of sending queries blindly to a class that may not report exceptions and since you might not be able to “catch” those errors, you will have a harder time finding the error logs, if you even have access to debug since the classes you are accessing may sometimes be closed (private or protected) from your code.  This is helpful when you use MYSQLi and need verbose errors:


MySQL PDO can be set similarly with the “setAttribute()” method, you can find out more at


– Aaron Belchamber

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *