• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

php db error not getting caught

lozina

Lifer
I am having trouble understanding why a database error is not getting caught by my code.

I am using PEAR for the db work and in this particular instance I am trying to select a column which does not exist. All that happens is that I get "DB Error: no such field" printed on the web browser. How do I catch this so I can handle the error and redirect to a user-friendly web page?

 
Wrap the calls in an exception handler (try block) then handling the error using a custom error handler (catch block) that can examine the error information from the error object.

Simply checking if(!runquery($sql)) is not sufficient as the called function may throw an exception inside without returning and this will fall back to the default root exception handler that prints naughty things on users browsers.
 
Back
Top