Page 1 of 1

What's the best way to locate errors?

Posted: Sat Mar 04, 2006 5:15 pm
by zeek
What is the best way to track errors in the following situation?

I have 8 classes, all of them use a 9th (database) class for handling mySQL queries. When I get a mySQL error, the script tells me on which line the error occured on the database class file, but this doesn't help me since it's always just the line in the database class that executes queries. I need to know in which method in which class the query passing through the database class originated. I can't figure out how to do this. Is there a good/standard way of handling this? Thanks in advance.

In case I explained this poorly, I've included an example below:

class.test.php:

Code: Select all

class test {
   ...
   function Query($query) {
      $result = mysql_query($query);
   }
   ...
}
class.test1.php:

Code: Select all

class test1 extends test {
   ...
   function SomeFunction() {
      ...
      parent::Query($query);
      ...
   }
   ...
}
class.test2.php:

Code: Select all

class test2 extends test {
   ...
   function AnotherFunction() {
      ...
      parent::Query($query);
      ...
   }
   ...
}
If a mySQL error occurs, how can I tell if the query originated in SomeFunction() or AnotherFunction() ? Thanks.

Posted: Sat Mar 04, 2006 5:24 pm
by josh

Posted: Sat Mar 04, 2006 5:32 pm
by zeek
jshpro2 wrote:checkout debug_backtrace()
thank you, that's exactly what I needed

Posted: Sat Mar 04, 2006 8:28 pm
by Ambush Commander
If you do your debugging on a local server, I'd recommend installing XDebug, as it automatically gives you the function stack when you hit errors.