Welcome Guest, Not a member yet? Register   Sign In
Sleightly enhanced profiler for queries

I tried to add this to the "Ignited Code" forum, but it won't submit. Sorry if this is in the wrong place.

In libraries/Profiler.php, we have modified it to output breaks before highlighted keywords for even nicer sql profiler output. Perhaps this would be beneficial to others, or worthy of adding to SVN.

$highlight = array('SELECT', 'FROM', 'WHERE', 'AND', 'ORDER BY', 'LEFT JOIN', ' OR', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'UNION' , 'INNER JOIN','GROUP BY');
                foreach ($this->CI->db->queries as $key => $val)
                    $val = htmlspecialchars($val, ENT_QUOTES);
                    $time = number_format($this->CI->db->query_times[$key], 4);
                    foreach ($highlight as $bold)
                        $break = $i==0 ? '' : '<br/>';
                        if (stristr($bold,'JOIN')) $break .= '&nbsp;&nbsp;&nbsp;&nbsp;';
                        $val = str_replace($bold, $break.'<strong>'.$bold.'</strong>', $val);    
                    $output .= "<tr><td width='1%' valign='top' style='color:#990000;font-weight:normal;background-color:#ddd;'>".$time."&nbsp;&nbsp;</td><td style='color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";

Outputs like this (with keywords bolded):
SELECT tblCredits.CreditID, CreditDate, CreditType, tblCredits.CreditAmount, Notes, Reference, SUM(tblItemCredits.CreditAmount) AS ItemCredit
FROM tblCredits
    INNER JOIN tblItemCredits ON tblItemCredits.CreditID = tblCredits.CreditID
    INNER JOIN tblInvoiceItems ON tblInvoiceItems.InvoiceItemID = tblItemCredits.InvoiceItemID
    INNER JOIN tblCreditType ON tblCreditType.CreditTypeID = tblCredits.CreditTypeID
WHERE tblInvoiceItems.InvoiceID = 136
GROUP BY tblCredits.CreditID, CreditDate, CreditType, Notes, Reference, tblCredits.CreditAmount

Messages In This Thread
Sleightly enhanced profiler for queries - by El Forum - 02-14-2008, 10:08 AM

Theme © iAndrew 2016 - Forum software by © MyBB