From ed3f4d3e4b4bfb8f480f96ad7c6750d5ea5b0674 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Sat, 9 Dec 2006 14:04:59 +0000 Subject: [PATCH] Add informations on query performance and affected rows git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1263 839d8a87-29fc-0310-9880-83ba4fa771e5 --- classes/xdb.php | 12 ++++++++++-- templates/database-debug.tpl | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/classes/xdb.php b/classes/xdb.php index d612ed8..9bda36c 100644 --- a/classes/xdb.php +++ b/classes/xdb.php @@ -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; diff --git a/templates/database-debug.tpl b/templates/database-debug.tpl index 944ad65..b168aea 100644 --- a/templates/database-debug.tpl +++ b/templates/database-debug.tpl @@ -37,6 +37,13 @@ {$query.error|nl2br} + {else} + + + INFO:
+ {$query.rows} enregistrement{if $query.rows > 1}s{/if} en {$query.exectime}ms + + {/if} {if $query.explain} -- 2.1.4