Jump to content

[SOLVED] debug_backtrace


surion

Recommended Posts

hi,

 

i have a function who logs my queries when they are performed:

 

function mysql_log_query($file,$line,$sql) {

  //do something with $file & $line

  return mysql_query($sql);

}

 

called this way:

$results = mysql_log_query(__FILE__,__LINE__,"some sql query");

 

 

i used to give __FILE__ & __LINE__ as arguments to to make the logging. but now i learned i can use debug_backtrace

 

so this becomes

 

 

function mysql_log_query($sql) {

  $backtrace = array();

  $backtrace = debug_backtrace();

  return mysql_query($sql);

}

 

now, i have the next problem:

 

sometimes i can get the line & file with $backtrace['file'] or $backtrace['line], YET, sometimes $backtrace becomes an ARRAY of arrays

 

For example:

 

what i want:

 

$backtrace = array('file => 'file', 'line' => 'line',... other backtrace info ...);

 

what i don't want but what i do get sometimes:

$backtrace = array(array(file => file, line => line, ... other backtrace info ...), array(file => file, line => line,... other backtrace info ...))

 

 

 

why does it sometimes become an array of arrays? how can i make sure that that does NOT happen, OR, is there a way to read those arrays of arrays correct? i mean, a function is at its current instance only called from 1 file, and or 1 line,... if you know what i mean,...

Link to comment
https://forums.phpfreaks.com/topic/129238-solved-debug_backtrace/
Share on other sites

it should always return an array of backtrace items, the number of items will depend on how deep you are. if you are inside a function called by another function, you will get two items. from the looks of it, you will always want the first item, so just use:

 

function mysql_log_query($sql) {
  list($backtrace) = debug_backtrace();
  return mysql_query($sql);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.