开发者

Warning mysql_fetch_array when I use MATCH, AGAINST in PHP/mySQL

I get this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQ开发者_开发百科L result resource

when I changed my code to this

$term = $_POST["term"];
$query = mysql_query("SELECT id FROM planet1 WHERE MATCH (title) AGAINST ('$term')");
while($row = mysql_fetch_array( $query )) {
echo $row['id'],'<br>';
} 


This happens when there is an error during the execution of the SQL query :

  • mysql_query() returns false
  • and that's not a resource as mysql_fetch_array() expects.


You should try calling mysql_error(), to have some information about the error that's caused by the execution of your MySQL :

$query = mysql_query("SELECT id FROM planet1 WHERE MATCH (title) AGAINST ('$term')");
if (!$query) {
    echo mysql_error();
    die;
}

Note: of course, this echo+die is OK while developping, but should never be present on a production server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜