Forum Moderators: open

Message Too Old, No Replies

How to use EXPLAIN with in PHP?

Mysql EXPLAIN statement query

         

tabish

5:33 pm on Apr 27, 2007 (gmt 0)

10+ Year Member



Hello,

Can anyone tell me how to use EXPLAIN witin my PHP-Mysql code? I dont want to run it from mysql root, I want to use it within my PHP.. what will be the syntax to echo EXPLAIN results in my browser?

Regards

coopster

3:48 pm on Apr 30, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Just as you would any other query. You will have to format it as you desire though ...
$stmt = "EXPLAIN SELECT * FROM table"; 
$rows = mysql_query($stmt);
if ($row = mysql_fetch_assoc($rows)) {
print '<pre>';
foreach ($row as $key => $value) {
print "$key: $value\n";
}
print '</pre>';
}