/[refeed]/trunk/introspect/query.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/introspect/query.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Wed Jul 5 00:27:49 2006 UTC (17 years, 10 months ago) by dpavlin
File size: 3715 byte(s)
make working copy of trunk
1 <?php
2 // vim: ts=4 foldcolumn=4 foldmethod=marker
3
4 ini_set("include_path",
5 join(PATH_SEPARATOR,
6 array(realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..'))),
7 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'PEAR'))),
8 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'Smarty'))),
9 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'magpierss'))),
10 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'RF'))),
11 ini_get("include_path"))));
12
13 require_once('config.php');
14 require_once('Utility.functions.php');
15 require_once("DB.php");
16
17 $dbh = & DB::connect(get_configured_dsn(),
18 array('debug' => REF_DB_DEBUG_LEVEL, 'portability' => DB_PORTABILITY_NONE));
19
20 if(DB::isError($dbh))
21 die(sprintf('<p><b>%s.</b></p><pre>%s</pre>', htmlspecialchars($dbh->getMessage()), htmlspecialchars($dbh->getDebugInfo())));
22
23 $dbh->setFetchMode(DB_FETCHMODE_OBJECT);
24
25 $q = "SELECT id, query, duration, context
26 FROM query_log
27 WHERE id = ".$dbh->quoteSmart($_GET['query'])."
28 LIMIT 1";
29
30 $res = $dbh->query($q);
31
32 if(DB::isError($res))
33 die(sprintf('<p><b>%s.</b></p><pre>%s</pre>', htmlspecialchars($res->getMessage()), htmlspecialchars($res->getDebugInfo())));
34
35 $query = $res->fetchRow();
36
37 $res = $dbh->query('EXPLAIN '.preg_replace('/\brb_/Ui', '', $query->query));
38
39 $explanations = array();
40
41 while($explanation = $res->fetchRow())
42 $explanations[] = $explanation;
43
44 ?>
45 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
46 "http://www.w3.org/TR/html4/loose.dtd">
47 <html>
48 <head>
49 <title>Query Log: Explain Query</title>
50 <link rel="stylesheet" href="style.css" type="text/css">
51 </head>
52 <body>
53 <p><a href="context.php?context=<?= urlencode($query->context) ?>">more in this context</a></p>
54 <h1>Query <?= $query->id ?></h1>
55 <h2><?= number_format($query->duration) ?> msec</h2>
56 <table border="0">
57 <tr>
58 <th>Select</th>
59 <th>Table</th>
60 <th>Type</th>
61 <th>Keys</th>
62 <th>Key</th>
63 <th>Len.</th>
64 <th>Ref.</th>
65 <th>Rows</th>
66 <th>Extra</th>
67 </tr>
68 <? foreach($explanations as $explanation): ?>
69 <tr>
70 <td class="value"><?= htmlspecialchars($explanation->select_type) ?></td>
71 <td class="value"><?= htmlspecialchars($explanation->table) ?></td>
72 <td class="value"><?= htmlspecialchars($explanation->type) ?></td>
73 <td class="value"><?= htmlspecialchars(implode(', ', explode(',', $explanation->possible_keys))) ?></td>
74 <td class="value"><?= htmlspecialchars($explanation->key) ?></td>
75 <td class="value"><?= htmlspecialchars($explanation->key_len) ?></td>
76 <td class="value"><?= htmlspecialchars(implode(', ', explode(',', $explanation->ref))) ?></td>
77 <td class="value"><?= htmlspecialchars($explanation->rows) ?></td>
78 <td class="value"><?= htmlspecialchars($explanation->extra) ?></td>
79 </tr>
80 <? endforeach ?>
81 </table>
82 <h2>Query</h2>
83 <pre><?= htmlspecialchars($query->query) ?></pre>
84 </body>
85 </html>

  ViewVC Help
Powered by ViewVC 1.1.26