Handling errors and warnings in PHP (PDO)
Sometimes errors happen when you attempt to
connect to a database or issue an SQL statement. The password for
your connection might be incorrect, a table you referred to in a SELECT
statement might not exist, or the SQL statement might be invalid. PDO
provides error-handling methods to help you recover gracefully from
the error situations.
Before you begin
You must set up the PHP environment on your system and enable the PDO and PDO_IBM extensions.
About this task
PDO gives you the option of handling errors as warnings, errors, or exceptions. However, when you create a new PDO connection object, PDO always throws a PDOException object if an error occurs. If you do not catch the exception, PHP prints a backtrace of the error information that might expose your database connection credentials, including your user name and password.
This procedure catches a PDOException object and handles the associated error.