Dbal Error Handling
From phpBB Development Wiki
DBAL error handling
There are three types of errors possible in DBAL:
1. Database extension is not present, connection cannot even be attempted.
2. Connection to the database failed.
3. Connection succeeded and a subsequent query/operation failed.
All database extensions provide a way of obtaining error information for errors in the last category, when a connection link identifier is available. Some database extensions provide a way of obtaining error information for connection errors, but some do not. For obvious reasons no database extension can report its lack of presence.
phpBB DBAL has a connect_error property that stores errors in the first category for all database extensions and in the second category for those database extensions that do not provide reporting of connection errors.
The error reporting logic in DBAL is therefore as follows:
1. If there is a connection link identifier, call the vendor-specific error reporting function.
2. If there is no connection link identifier, but the database extension provides a function reporting connection errors, and that function exists, call that function.
3. If there is no connection link identifier, fall back on connect_error property.
Note that the connect_error property is only used when there is no established connection.
Behavior by Database Extension
ibase_errmsg returns connection errors.
mysql_error requires an established connection.
mysqli_connect_error returns connection errors.
pg_last_error requires an established connection.