on se dépèche d'utilise la killer feature de debug sql intégré à la lib diogenes :)
authorx2000habouzit <x2000habouzit>
Fri, 20 Feb 2004 11:12:52 +0000 (11:12 +0000)
committerx2000habouzit <x2000habouzit>
Fri, 20 Feb 2004 11:12:52 +0000 (11:12 +0000)
htdocs/mescontacts.php
include/xorg.common.inc.php
include/xorg.page.inc.php
templates/database-debug.tpl [new file with mode: 0644]

index 19d19b4..2b91c7e 100644 (file)
@@ -52,9 +52,6 @@ $sql = "SELECT contact AS id,
         LEFT  JOIN geoloc_region  AS gr  ON (adr.pays = gr.a2 AND adr.region = gr.region)
         WHERE c.uid = {$_SESSION['uid']}
         ORDER BY a.nom, a.prenom";
-$globals->db->query($sql);
-echo mysql_error();
-
 $page->mysql_assign($sql,'contacts','nb_contacts');
 
 $page->run();
index 01a32aa..cf58913 100644 (file)
@@ -28,4 +28,6 @@ session_start();
 // connect to database
 $globals->dbconnect();
 $conn = $globals->db->connect_id;
+if($site_dev)
+    $globals->db->trace_on();
 ?>
index 10d63dd..1934041 100644 (file)
@@ -60,13 +60,15 @@ class XorgPage extends DiogenesCorePage {
     }
 
     function run($append_to_id="") {
-        global $baseurl, $site_dev;
+        global $baseurl, $site_dev, $globals;
         if($this->_page_type == NO_SKIN)
             parent::display($this->_tpl);
         else {
             if(isset($_SESSION['suid'])) $this->caching=false;
             $id = $this->make_id($append_to_id);
             if($site_dev) {
+                echo $globals->db->trace_format($this, 'database-debug.tpl');
+
                 $this->assign('validate', urlencode($baseurl.'/valid.html'));
                 $result = $this->fetch('skin/'.$_SESSION['skin'], $id);
                 $fd = fopen($this->cache_dir."valid.html","w");
diff --git a/templates/database-debug.tpl b/templates/database-debug.tpl
new file mode 100644 (file)
index 0000000..9c165a6
--- /dev/null
@@ -0,0 +1,40 @@
+{dynamic}
+
+{foreach item=query from=$trace_data}
+<br />
+<table class="bicol" style="width: 75%; font-family: fixed">
+  <tr class="impair">
+    <td><strong>QUERY:</strong><br />{$query.query|nl2br}</td>
+  </tr>
+  {if $query.error}
+  <tr>
+    <td><strong>ERROR:</strong><br />{$query.error|nl2br}</td>
+  </tr>
+  {/if}
+</table>
+<table class="bicol" style="width: 75%; font-family: fixed">
+  <tr>
+    <th>table</th>
+    <th>type</th>
+    <th>possible_keys</th>
+    <th>key</th>
+    <th>key_len</th>
+    <th>ref</th>
+    <th>rows</th>
+    <th>extra</th>
+  </tr>
+  <tr class="impair">
+    <td class="center">{$query.explain.table}</td>
+    <td class="center">{$query.explain.type}</td>
+    <td class="center">{$query.explain.possible_keys}</td>
+    <td class="center">{$query.explain.key}</td>
+    <td class="center">{$query.explain.key_len}</td>
+    <td class="center">{$query.explain.ref}</td>
+    <td class="center">{$query.explain.rows}</td>
+    <td class="center">{$query.explain.Extra}</td>
+  </tr>
+</table>
+<br />
+{/foreach}
+
+{/dynamic}