Http://blog.sina.com.cn/s/blog_4f9fc6e10100rhn5.html
Today the site appears a bug, and then directly in the database class to write the log, see which SQL is out of the question, the SQL statement is found, but do not know where this SQL statement from, so I think, if there is a way to see the current running method is called by which method, And how the previous method called, and so on, to find the entry address. But I have also thought about it before, and also searched the Internet, that is, did not find the relevant method, today a colleague (predecessors) said Java inside this debugging used is very common, called this kind of stack debugging, I was on the web search PHP stack. I found it, and then write my own way out.
Call the stack function to find the source of the calling function to facilitate debugging
function Print_stack_trace ()
{
$array =debug_backtrace ();
Print_r ($array);//information is complete
unset ($array [0]);
foreach ($array as $row)
{
$html. = $row [' file ']. $row [' line ']. ' Line, calling method: '. $row [' function ']. " <p> ";
}
return$html;
}
I call this method in the core query function of my database and print the results as follows:
d:\wamp\www\meilele\includes\cls_mysql.php:471 line, calling method: Query
d:\wamp\www\meilele\includes\cls_mysql.php:507 line, calling method: GetAll
d:\wamp\www\meilele\includes\lib_common.php:732 line, calling method: Getallcached
D:\wamp\www\meilele\includes\init.php:113 line, calling method: Load_config
D:\wamp\www\meilele\index.php:4 line, calling method: Include_once
At a glance, has been found the entrance, too strong. There's one more way to debug later.
Or use the following method:
$e = new Exception;
Var_dump ($e->gettraceasstring ());