View Full Version : Advice on Error Handler ...

12-26-2007, 04:32 PM
We utilize several Includes which output
results from a MySQL script.

The Includes look like this:

<? include "http://www.site.com/php/psDynamic/psDynamic.php?command=view&cid=89" ; ?>

This code is trouble-free until we encounter the occasional SQL error.
If an error occurs, (obviously) a MySQL error displays and screws up the screen.

What I'd like to do is add some error handling.

Something like...

Try the Include
If result contains text 'failed' or '503', then do not display, then exit.
Display Include

Is this possible?

12-26-2007, 07:42 PM
I think you are looking for this. Just enter @ operator before the include function or you can use this for a custom error message like this

$test = @include "http://www.site.com/php/psDynamic/psDynamic.php?command=view&cid=89";
echo $test;
echo 'sorry: the page cannot be retrive now , u may try later';

12-26-2007, 08:59 PM
You should do your error handling inside each include that accesses the database. Your application should handle errors in a unified way as an application.

I assume that you are using the die() function in conjunction with mysql_error() if you are getting actual errors echoed out. Using die() is a decidedly user-unfriendly and non-HTML compliant way to handle errors. Echoing out direct mysql errors in production is insecure. If you are getting numerous failed quiries then there is something much more serious going on in your code. Syntax errors isn't the only reason that queries can fail, but it's the most common. Conditions that cause syntax errors need to be cleaned up first and foremost.