I'm trying to do a simple EXPLAIN query in MySQL from a php script:
$link = mysql_connect($dbHost, $dbUser, $dbPass);
$database = "test";
$sql = "SELECT * from t t1, t t2";
mysql_select_db($database, $link);
$explainSQL = "EXPLAIN " . $sql;
echo $explainSQL;
$explainResult = mysql_query($explainSQL, $link);
while($explainRow = mysql_fetch_array($explainResult)){
$tables[] = $explainRow;
}
print_r($tables);
But I get this:
EXPLAIN SELECT * from t t1, t t2
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\xampp\htdocs\ajaxMyTop\ajaxMyTop\explain.php on line 9
If I run the echo'd explainSQL directly in MySQL, it works fine.
Is there something special I have to use to work with result-sets from EXPLAIN statements?