aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-13 17:48:06 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-13 17:48:06 +0000
commit4b7d06e1f39331b1fbbcfeb79f2a216544e07c8a (patch)
tree7ca5e1160bff44d382eb44de74194df15838b084 /engine
parentcb31c35edf0f1babd6ae77224eedc539a55631fa (diff)
downloadelgg-4b7d06e1f39331b1fbbcfeb79f2a216544e07c8a.tar.gz
elgg-4b7d06e1f39331b1fbbcfeb79f2a216544e07c8a.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Use $CONFIG->debug = true to enable query profiling git-svn-id: https://code.elgg.org/elgg/trunk@214 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/database.php32
1 files 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)) {