[REVIEW] database->explain

Last reviewed: Not reviewed
phpDocumentor

database->explain

This is a diagnostic function that performs an SQL EXPLAIN on the current SQL query string.  The result is returned in an HTML table.

Syntax

string explain ( )

Examples

Example:

$query = "SELECT id"
       . "\n FROM #__menu"
       . "\n WHERE menutype='mainmenu'"
       . "\n AND published='1'"
       . "\n ORDER BY parent, ordering";
 
$database->setQuery( $query );
echo $database->explain ();

might output:

<div style="background-color:#FFFFCC" align="left">
<table cellspacing="1" cellpadding="2" border="0" bgcolor="#000000" align="center">
<pre>EXPLAIN SELECT id
 FROM mos_menu
 WHERE menutype='mainmenu'
 AND published='1'
 ORDER BY parent, ordering</pre>
  <tr>
  <th bgcolor="#ffffff">table</th><th bgcolor="#ffffff">type</th>
  <th bgcolor="#ffffff">possible_keys</th>
  <th bgcolor="#ffffff">key</th>
  <th bgcolor="#ffffff">key_len</th>
  <th bgcolor="#ffffff">ref</th>
  <th bgcolor="#ffffff">rows</th>
  <th bgcolor="#ffffff">Extra</th>
  </tr>
  <tr>
  <td bgcolor="#ffffff">mos_menu</td>
  <td bgcolor="#ffffff">ref</td>
  <td bgcolor="#ffffff">menutype</td>
  <td bgcolor="#ffffff">menutype</td>
  <td bgcolor="#ffffff">26</td>
  <td bgcolor="#ffffff">const</td>
  <td bgcolor="#ffffff">13</td>
  <td bgcolor="#ffffff">where used; Using filesort</td>
  </tr>
</table>
<br /> </div>
 

which renders as:

EXPLAIN SELECT id
 FROM mos_menu
 WHERE menutype='mainmenu'
 AND published='1'
 ORDER BY parent, ordering
tabletypepossible_keyskeykey_lenrefrowsExtra
mos_menurefmenutypemenutype26const13where used; Using filesort

 

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Monday, 25 December 2006 )