What's the best way to locate errors?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

What's the best way to locate errors?

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

Post by zeek »

jshpro2 wrote:checkout debug_backtrace()
thank you, that's exactly what I needed
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
Post Reply