RE: Using DESCRIBE and/or EXPLAIN in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Is it possible to return the results of a query that uses the DESCRIBE
> and/or
> EXPLAIN command(s)?  My attempts using mysql_query() have so far been
> fruitless
> and a review of http://www.php.net/manual/en/ref.mysql.php didn't
provide
> any
> answers.  Your assistance is appreciated.  Thanks.
> 
> FWIW, I know that I can achieve a similar result by combining
> mysql_list_fields
> with mysql_field_type but I'm curious as to whether this can be done
with
> a
> single query.  Thanks again.

You treat the result just like any other query:

$result = mysql_query("EXPLAIN ... ");
$row = mysql_fetch_assoc($result);

echo $row['table'];
echo $row['type'];

etc...

If more than one row is returned, you'll have to loop through them, but
it's no different that any other query. Best bet is to run the query
from the command line to you can tell what columns are returned. Make
sure you match the case of the columns returned when using an
associative array, too. i.e. $row['table'] instead of $row['Table']...

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux