From 4b7d06e1f39331b1fbbcfeb79f2a216544e07c8a Mon Sep 17 00:00:00 2001 From: icewing Date: Thu, 13 Mar 2008 17:48:06 +0000 Subject: Marcus Povey * Use $CONFIG->debug = true to enable query profiling git-svn-id: https://code.elgg.org/elgg/trunk@214 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/database.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/engine/lib/database.php b/engine/lib/database.php index 158738185..626def70b 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -104,6 +104,18 @@ return $dblink['readwrite']; } + } + + /** + * Explain a given query, useful for debug. + */ + function explain_query($query, $link) + { + if ($result = mysql_query("explain " . $query, $link)) { + return mysql_fetch_object($result); + } + + return false; } /** @@ -115,12 +127,18 @@ function get_data($query, $callback = "") { - global $dbcalls; + global $CONFIG, $dbcalls; $dblink = get_db_link('read'); $resultarray = array(); - $dbcalls++; + $dbcalls++; + + if ((isset($CONFIG->debug)) && ($CONFIG->debug==true)) + { + error_log("--- DB QUERY --- $query"); + error_log("--- EXPLAINATION --- " . print_r(explain_query($query,$dblink), true)); + } if ($result = mysql_query($query, $dblink)) { while ($row = mysql_fetch_object($result)) { @@ -149,11 +167,17 @@ function get_data_row($query) { - global $dbcalls; + global $CONFIG, $dbcalls; $dblink = get_db_link('read'); - $dbcalls++; + $dbcalls++; + + if ((isset($CONFIG->debug)) && ($CONFIG->debug==true)) + { + error_log("--- DB QUERY --- $query"); + error_log("--- EXPLAINATION --- " . print_r(explain_query($query,$dblink), true)); + } if ($result = mysql_query($query, $dblink)) { while ($row = mysql_fetch_object($result)) { -- cgit v1.2.3