By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,203 Members | 1,383 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,203 IT Pros & Developers. It's quick & easy.

mysql class, error handling

P: n/a
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__,
$line=__LINE__)
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
function?
Thanks in advance
Nikos

Jul 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
*** paranic escribió/wrote (12 Jul 2006 03:37:29 -0700):
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
function?
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.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 12 '06 #2

P: n/a
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.

Jul 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.