-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMY_Profiler.php
More file actions
92 lines (75 loc) · 3.05 KB
/
Copy pathMY_Profiler.php
File metadata and controls
92 lines (75 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* Created by Martin Wernståhl on 2009-04-30.
* Copyright (c) 2009 Martin Wernståhl.
* All rights reserved.
*/
/**
* Modified profiler for CodeIgniter, which fetches the run queries from RapidDataMapper.
*/
class MY_Profiler extends CI_Profiler
{
/**
* Returns the list of run queries
*
* @return string
*/
function _compile_queries()
{
$dbs = array();
// is RapidDataMapper loaded?
if(class_exists('Db'))
{
// get all the active instances
$dbs = Db::getLoadedConnections();
}
if (count($dbs) == 0)
{
$output = "\n\n";
$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= "\n";
$output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>';
$output .= "\n";
$output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
$output .="<tr><td width='100%' style='color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n";
$output .= "</table>\n";
$output .= "</fieldset>";
return $output;
}
// 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', '(', ')');
$output = "\n\n";
foreach($dbs as $name => $db)
{
$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= "\n";
$output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database').': '.$name.' '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).' </legend>';
$output .= "\n";
$output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
if(count($db->queries) == 0)
{
$output .= "<tr><td width='100%' style='color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\n";
}
else
{
foreach($db->queries as $key => $val)
{
$time = number_format($db->query_times[$key], 4);
$val = highlight_code($val, ENT_QUOTES);
foreach($highlight as $bold)
{
$val = str_replace($bold, '<strong>'.$bold.'</strong>', $val);
}
$output .= "<tr><td width='1%' valign='top' style='color:#990000;font-weight:normal;background-color:#ddd;'>".$time." </td><td style='color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";
}
}
$output .= "</table>\n";
$output .= "</fieldset>";
}
return $output;
}
}
/* End of file MY_Router.php */
/* Location: ./application/libraries/MY_Router.php */