Hi,
Is there a way of using and displaying the outcome of a query using EXPLAIN within PHP?
Thanks
| SitePoint Sponsor |



Hi,
Is there a way of using and displaying the outcome of a query using EXPLAIN within PHP?
Thanks
Michael Laddie
Durham based Web Developer
What the heck do you mean? please explain



All I know about EXPLAIN is to use it in the 'dos' interface.
How can I use it within a PHP script to show what I would see in the 'dos' interface on a web page?
Michael Laddie
Durham based Web Developer


Let's not call it the "dos" interface, DOS was an operating system. It's the mysql client, or a command line interface
You can do exactly what you do with SELECT queries, it'll work with EXPLAIN:
PHP Code:mysql_connect('localhost', 'user', 'pass');
mysql_select_db('db');
$res = mysql_query('EXPLAIN SELECT id FROM purchases');
while ($row = mysql_fetch_assoc($res))
print_r($row);
Code:Array ( [id] => 1 [select_type] => SIMPLE [table] => purchases [type] => index [possible_keys] => [key] => PRIMARY [key_len] => 4 [ref] => [rows] => 953 [Extra] => Using index )
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.
Bookmarks