| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * WiND - Wireless Nodes Database |
|---|
| 4 | * |
|---|
| 5 | * Copyright (C) 2005 Nikolaos Nikalexis <winner@cube.gr> |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; version 2 dated June, 1991. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | * |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | ob_start(); |
|---|
| 23 | |
|---|
| 24 | define("ROOT_PATH","../"); |
|---|
| 25 | |
|---|
| 26 | include_once(ROOT_PATH."globals/common.php"); |
|---|
| 27 | if ($vars['debug']['enabled'] == FALSE) die("WiND: Debug mode is not enabled. Check the config file.") ; |
|---|
| 28 | |
|---|
| 29 | class mysql_debug extends mysql { |
|---|
| 30 | |
|---|
| 31 | function query ($query) { |
|---|
| 32 | $mt = $this->getmicrotime(); |
|---|
| 33 | $return = parent::query($query); |
|---|
| 34 | $time = $this->getmicrotime() - $mt; |
|---|
| 35 | $r=mysql_query('EXPLAIN '.$query, $this->mysql_link); |
|---|
| 36 | $explain=$this->result_to_data($r); |
|---|
| 37 | $ex_echo .= '<table border="1">'; |
|---|
| 38 | foreach ($explain as $key => $value) { |
|---|
| 39 | if ($key == 0) { |
|---|
| 40 | $ex_echo .= '<tr>'; |
|---|
| 41 | foreach ($value as $key2 => $value2) { |
|---|
| 42 | $ex_echo .= '<td>'.$key2.'</td>'; |
|---|
| 43 | } |
|---|
| 44 | $ex_echo .= '</tr>'; |
|---|
| 45 | } |
|---|
| 46 | $ex_echo .= '<tr>'; |
|---|
| 47 | foreach ($value as $key2 => $value2) { |
|---|
| 48 | $ex_echo .= '<td>'.$value2.'</td>'; |
|---|
| 49 | } |
|---|
| 50 | $ex_echo .= '</tr>'; |
|---|
| 51 | } |
|---|
| 52 | $ex_echo .= '</table>'; |
|---|
| 53 | echo '<tr><td>'.$query.'</td><td>'.$ex_echo.'</td><td>'.($time).'</td></tr>'; |
|---|
| 54 | return $return; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | $db = new mysql_debug($vars['db']['server'], $vars['db']['username'], $vars['db']['password'], $vars['db']['database']); |
|---|
| 60 | |
|---|
| 61 | if ($db->error) { |
|---|
| 62 | die("WiND MySQL database error: $db->error_report"); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | include_once(ROOT_PATH."includes/main.php"); |
|---|
| 66 | |
|---|
| 67 | echo '<table border="1">'; |
|---|
| 68 | $db->query("FLUSH QUERY CACHE"); |
|---|
| 69 | $db->query("RESET QUERY CACHE"); |
|---|
| 70 | $main = new main; |
|---|
| 71 | $main->output(); |
|---|
| 72 | echo '</table>'; |
|---|
| 73 | |
|---|
| 74 | ob_end_flush(); |
|---|
| 75 | |
|---|
| 76 | ?> |
|---|