From 2dd61d53c6c8c69e1455c9fb35065ed2b4571ef6 Mon Sep 17 00:00:00 2001 From: patrioticcow Date: Thu, 10 Jul 2014 13:18:45 -0700 Subject: [PATCH] Imporve Database.php it looks like `EXPLAIN connect` doesn't work and `$explain` sometimes comes in as a object --- .../Plugin/Debug/Plugin/Database.php | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php b/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php index b1922b0..4795dad 100644 --- a/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php +++ b/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php @@ -163,25 +163,29 @@ public function getProfile() # Run explain if enabled, supported adapter and SELECT query if ($this->_explain && $supportedAdapter) { $queries .= ""; - - foreach ($adapter->fetchAll('EXPLAIN '.$profile->getQuery()) as $explain) { - $queries .= "
"; - $explainData = array( - 'Type' => $explain['select_type'] . ', ' . $explain['type'], - 'Table' => $explain['table'], - 'Possible keys' => str_replace(',', ', ', $explain['possible_keys']), - 'Key used' => $explain['key'], - ); - if ($explain['Extra']) { - $explainData['Extra'] = $explain['Extra']; - } - $explainData['Rows'] = $explain['rows']; - - $explainEnd = end($explainData); - foreach ($explainData as $key => $value) { - $queries .= "$key: $value
\n"; + $queries .= ""; // better layout + $q = $profile->getQuery(); + if ($q !== 'connect') { // can't explain 'connect' + foreach ($adapter->fetchAll('EXPLAIN '.$profile->getQuery()) as $explain) { + $explain = (array)$explain; // in case is a object + $queries .= "
"; + $explainData = array( + 'Type' => $explain['select_type'] . ', ' . $explain['type'], + 'Table' => $explain['table'], + 'Possible keys' => str_replace(',', ', ', $explain['possible_keys']), + 'Key used' => $explain['key'], + ); + if ($explain['Extra']) { + $explainData['Extra'] = $explain['Extra']; + } + $explainData['Rows'] = $explain['rows']; + + $explainEnd = end($explainData); + foreach ($explainData as $key => $value) { + $queries .= "$key: $value
\n"; + } + $queries .= "
"; } - $queries .= "
"; } } @@ -198,4 +202,4 @@ protected function _addQuotes(&$value, $key) { $value = "'" . $value . "'"; } -} \ No newline at end of file +}