protected _compile_queries ( ) : string | ||
return | string |
protected function _compile_queries()
{
$dbs = array();
$output = array();
// Let's determine which databases are currently connected to
foreach (get_object_vars($this->CI) as $CI_object) {
if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB')) {
$dbs[] = $CI_object;
}
}
if (count($dbs) == 0) {
return $this->CI->lang->line('profiler_no_db');
}
// Load the text helper so we can highlight the SQL
$this->CI->load->helper('text');
// Key words we want bolded
$highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')');
$total = 0;
// total query time
foreach ($dbs as $db) {
foreach ($db->queries as $key => $val) {
$time = number_format($db->query_times[$key], 4);
$total += $db->query_times[$key];
foreach ($highlight as $bold) {
$val = str_replace($bold, '<b>' . $bold . '</b>', $val);
}
$output[][$time] = $val;
}
}
if (count($output) == 0) {
$output = $this->CI->lang->line('profiler_no_queries');
} else {
$total = number_format($total, 4);
$output[][$total] = 'Total Query Execution Time';
}
return $output;
}
protected function _compile_queries() { $output = array(); $input = parent::_compile_queries(); if (!empty($input)) { $this->CI->load->helper('text'); $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'); foreach ($input as $database => $info) { $database = $this->base_uri($database); $output[$database] = array('name' => array_shift($info), 'total' => $this->milliseconds(array_shift($info))); foreach ($info as $db) { $db['query'] = highlight_code($db['query']); foreach ($highlight as $bold) { $db['query'] = str_replace($bold, '<strong>' . $bold . '</strong>', $db['query']); } $output[$database][] = array('query' => $db['query'], 'time' => $this->milliseconds($db['time'])); } } } return $output; }