Add informations on query performance and affected rows
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 9 Dec 2006 14:04:59 +0000 (14:04 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 9 Dec 2006 14:04:59 +0000 (14:04 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1263 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/xdb.php
templates/database-debug.tpl

index d612ed8..9bda36c 100644 (file)
@@ -23,7 +23,8 @@ class XDB
 {
     var $_trace_data = array();
 
-    public static function _prepare($args) {
+    public static function _prepare($args)
+    {
         $query    = array_map(Array('XDB', '_db_escape'), $args);
         $query[0] = str_replace('{?}', '%s', str_replace('%',   '%%', $args[0]));
         return call_user_func_array('sprintf', $query);
@@ -54,7 +55,8 @@ class XDB
         return $res;
     }
 
-    public static function _query($query) {
+    public static function _query($query)
+    {
         global $globals;
 
         if ($globals->debug & 1) {
@@ -65,12 +67,18 @@ class XDB
             }
             $trace_data = array('query' => XDB::_reformatQuery($query), 'explain' => $explain);
             @mysql_free_result($_res);
+            $time_start = microtime();
         }
 
         $res = mysql_query($query);
 
         if ($globals->debug & 1) {
+            list($ue, $se) = explode(" ", microtime());
+            list($us, $ss) = explode(" ", $time_start);
+            $time = intval((($ue - $us) + ($se - $ss)) * 1000);            
             $trace_data['error'] = mysql_error();
+            $trace_data['exectime'] = $time;
+            $trace_data['rows'] = @mysql_num_rows() ? mysql_num_rows() : mysql_affected_rows();
             $GLOBALS['XDB::trace_data'][] = $trace_data;
             if (mysql_errno()) {
                 $GLOBALS['XDB::error'] = true;
index 944ad65..b168aea 100644 (file)
       {$query.error|nl2br}
     </td>
   </tr>
+  {else}
+  <tr>
+    <td>
+      <strong>INFO:</strong><br />
+      {$query.rows} enregistrement{if $query.rows > 1}s{/if} en {$query.exectime}ms
+    </td>
+  </tr>
   {/if}
 </table>
 {if $query.explain}