开发者

Searching with MATCH(), AGAINST() and AS score with mysqli and php

Below is the code I am using to search my table. I have made the relevant columns FULLTEXT in the table. This doesn't return me anything. Can someone tell me what it is that i'm doing wrong? Thanks in advance.

$sql = 'SELECT id, person_name, classroom, school, MATCH (person_name, classroom, school) AGAINST (?) AS score FROM images WHERE MATCH(person_name, classroom, school) AGAINST(?) ORDER BY score DESC';

$stmt = $db_connection->prepar开发者_开发问答e($sql);

$stmt->bind_param('ss',$keyword,$keyword);

$stmt->execute();

$stmt->store_result();
$stmt->bind_result($id,$uname,$class,$school);

$xml = "<data>".PHP_EOL;

while($stmt->fetch()){

    $xml .= "   <person>".PHP_EOL;
    $xml .= "       <id>$id</id>".PHP_EOL;
    $xml .= "       <name>$uname</name>".PHP_EOL;
    $xml .= "       <class>$class</class>".PHP_EOL;
    $xml .= "       <school>$school</school>".PHP_EOL;
    $xml .= "   </person>".PHP_EOL;

}

$xml .= "</data>";

echo $xml;

Below is an image of the indexes of the table:

Searching with MATCH(), AGAINST() and AS score with mysqli and php

(source: bionic-comms.co.uk)

It would appear that the problem lies in trying to bind the parameters before executing the query. Can someone confirm that you can use this query with prepared statements?


Offhand, it would look like your SQL's got a syntax error: DES at the end should be DESC. You have no error checking on the prepare/execute calls, so there's no way to tell if either spit out an error.

If that's just a typo entering it here and the real query's fine, what happens when you run it manually in phpmyadmin? Any results there?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜