mysql class, error handling

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi there

i suppose we have the following class

file database.php
class InSQL
    function query($query, $link_identifier=null)
        global $query_totals;

        $query_start = microtime(true);
        $return = mysql_query($query, $link_identifier);
        $query_stop = microtime(true);

        $query_totals[] = ($query_stop - $query_start);

        return $return;

i call the query from another file
file sample.php
$result = InSQL::query($sql, $localdb);

when a mysql error occur php reports mysq error at file database.php
line x.
i whant without modifing the form of calling the queryies to display
the correct error with the caller file and the caller line.

one solution is to modify the calling line to $result =
InSQL::query($sql, $localdb, __FILE__, __LINE__);
so if an error occur i will have the file and line where i called the
query. but i dont whant to make the query calling line so complicated.

the other solution is to change the query function as folows:
function query($query, $link_identifier=null, $file=__FILE__,
and call the query as always, but this reports the database.php file
and the function query() line.

is there any way to have correct error reporting without printing the
query on the browser and without modifing the way i call the query

Thanks in advance

Re: mysql class, error handling

*** paranic escribió/wrote (12 Jul 2006 03:37:29 -0700):
Quoted text here. Click to load it

You can use trigger_error() to raise custom errors. Then, you can write a
custom error handling function and assign it with set_error_handler(). This
function allows you to do whatever you want with error messages: print on
screen, log to file...

PHP 5 has a new exception system. I haven't tried it but I suppose its
similar to those in Java or JavaScript.

-+ - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web:
+- Mi web de humor con rayos UVA:

Re: mysql class, error handling

finaly i think i got my solution

it is debug_backtrace()
and debug_print_backtrace()
where it gives me where the error is originated and i can make my own
custom error handling function for my sql class.

thanks a lot.

Site Timeline