Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codeigniter profiler, where are the queries coming from ?
<?php
// from http://php.net/manual/en/function.debug-backtrace.php#111255
// adapted for codeigniter
// database/DB_driver.php method query()
//...
// Save the query for debugging
if ($this->save_queries == TRUE)
{
$this->queries[] = $sql . "\n# ".get_caller_info();
}
// get_caller_info funtion somewhere in global scope
function get_caller_info() {
$c = '';
$file = '';
$line = '';
$func = '';
$class = '';
$trace = debug_backtrace();
// if (isset($trace[2])) {
// $file = $trace[1]['file'];
// $line = $trace[1]['line'];
// $func = $trace[2]['function'];
// if ((substr($func, 0, 7) == 'include') || (substr($func, 0, 7) == 'require')) {
// $func = '';
// }
// } else if (isset($trace[1])) {
// $file = $trace[1]['file'];
// $line = $trace[1]['line'];
// $func = '';
// }
if (isset($trace[3]['class'])) {
$class = $trace[3]['class'];
$func = $trace[3]['function'];
$file = $trace[2]['file'];
$line = $trace[2]['line'];
} else if (isset($trace[2]['class'])) {
$class = $trace[2]['class'];
$func = $trace[2]['function'];
$file = $trace[1]['file'];
$line = $trace[1]['line'];
}
if ($file != ''){
if (strpos($file,BASEPATH)===0) {
$file = 'CI ' . str_replace(BASEPATH,'',$file);
}elseif (strpos($file,APPPATH)===0) {
$file = 'APP ' . str_replace(APPPATH,'',$file);
}else {
$file = 'UNKNOWN ' . basename($file);
}
}
$c = $file . ": ";
$c .= ($class != '') ? ":" . $class . "->" : "";
$c .= ($func != '') ? $func . "(): " : "";
$c .= ' Line: '.$line;
return($c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.