Greetings

Some years ago I made a academic project using PHP and Informix. To catch the messages from Informix and PHP I used the lines on the beggining of script

$old_error_handler = set_error_handler("myErrorHandler");

function myErrorHandler ($errno, $errstr, $errfile, $errline) {
}

and in the end of script I used

restore_error_handler();

This worked. Now I'm using MySQL and PHP 4.3.4 on a project and these lines not work. I use this but I still see the warning messages on displayed on browser (if, for example, the mysql connection fails). How can I trap these messages? What is the technique?

Thank you

Sérgio

    use [man]error_reporting[/man] to turn off errors

    error_reporting(E_NONE);

      Check your code and make sure that the set_error_handler line is being called. PHP's error handling has not changed in quite some time.

      Be aware that syntax errors are not caught as they get generated before the code is executed but certainly connection errors will be.

        Originally posted by sgalmeida
        This worked. Now I'm using MySQL and PHP 4.3.4 on a project and these lines not work. I use this but I still see the warning messages on displayed on browser (if, for example, the mysql connection fails).

        If it really is a warning message, then [man]set_error_handler/man will work. Either the line to do that is not being called in your script, or another error handler is being set later on and overriding your setting.

        However, if the code works like so:

        mysql_connect(...) or die("Could not connect to DB.")

        then you will get "Could not connect to DB" printed no matter what you do with [man]set_error_handler/man. There is no way to trap [man]die/man messages. If you need to trap the condition, use [man]trigger_error/man instead of [man]die/man.

          Write a Reply...