[eluser]_asdf[/eluser]
I'm kind of lazy, or I'd roll this out to a separate file rather than hack the core, but whatever, its a two minute job, and its the kind of thing that ought to be in the profiler core anyway, really.
So yeah, when in development, I always run every controller with profiling on (which is kind of a pain, BTW.) so that I can see whats going on. As an addition, its kind of useful to see whats happening to queries behind the scenes, hence the delightful EXPLAIN SQL syntax. But I don't want to print_r or copypaste every query to run against the database.
So I'll make CI do it for me. In a hacky, monkeypatch'd fashion.
So, should anyone else feel like making upgrading from 1.6.1 harder, join me now as we corrupt
Libraries/Profiler.php (nb: I may actually override the class method in a separate file, if I can be bothered)
Code:
Line 132: $val = htmlspecialchars($val, ENT_QUOTES);
// change to:
$explain = $val; // for EXPLAIN bit later. htmlspecialchars breaks queries, and decode isn't an option until PHP5 >
$val = htmlspecialchars($val, ENT_QUOTES);
Code:
Line 141: $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";
// directly after that, lets paste in some more hacky code!
// explain select statements
if (strpos($explain, 'SELECT') !== false)
{
$r = $this->CI->db->query('EXPLAIN ' . $explain);
$r = $r->result_array();
$output .= "<tr><td width='1%' style='font-weight:normal;'> </td><td style='color:#000;font-weight:normal;'>";
foreach ($r as $explain)
{
$output .= "<table cellpadding='3' width='100%' style='border-top: 1px solid #ddd;margin-bottom: 10px'>";
next($explain); // pop id off, because who cares?
while (list($key, $val) = each($explain))
{
if (!empty($val)) // only display non-empty elements
{
$output .= "<tr><td style='color:#990000;' width='100'>" . $key . "</td><td>" . $val . "</td></tr>";
}
}
$output .= "</table>\n";
}
$output .= "</td></tr>\n";
}
and that should be it. Now you can enjoy all the benefits of EXPLAINing your queries (and the hassles of upgrading CI in the future), and finding out why that query is taking so blasted long. Its no 'slow queries' log, but its a start.