Jump to content

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);
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.