source: trunk/debug/mysql.php @ 152

Revision 152, 2.1 KB checked in by Winner, 6 years ago (diff)

Fix: Windows CRLF converted to LF (linux).

Line 
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
22ob_start();
23
24define("ROOT_PATH","../");
25
26include_once(ROOT_PATH."globals/common.php");
27if ($vars['debug']['enabled'] == FALSE) die("WiND: Debug mode is not enabled. Check the config file.") ;
28
29class 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
61if ($db->error) {
62        die("WiND MySQL database error: $db->error_report");
63}
64
65include_once(ROOT_PATH."includes/main.php");
66
67echo '<table border="1">';
68$db->query("FLUSH QUERY CACHE");
69$db->query("RESET QUERY CACHE");
70$main = new main;
71$main->output();
72echo '</table>';
73
74ob_end_flush();
75
76?>
Note: See TracBrowser for help on using the repository browser.