php为sql全文搜索准备语句

时间:2015-10-25 01:12:02

标签: php mysql

大家好我需要帮助,我试图使用PHP全文搜索使用PHP准备语句这是我试过的

//sql 1: $sql = "SELECT title FROM business WHERE MATCH (title,description) AGAINST ('?')";
//sql 2: $sql = "SELECT title FROM business WHERE MATCH (title,description) AGAINST (:string)";
//bind 1: $stmt->bind_param("s", $q);
//bind 2: $stmt->bind_param(":string", $q)'

$q = $_POST['name'];
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $q);//tried both binds
$stmt->execute();
$stmt->bind_result($title);
while ($stmt->fetch()){
    @$result .= '<a href="'.$title.'" target="_blank"> <div class="dproped container">'.$title.'</div> </a>';
}
$stmt->close();
echo json_encode(array('searchresult' => $result));

sql 1:返回null 而sql 2:返回错误500(在非对象上调用成员函数bindParam())。我究竟做错了什么?有人可以帮我解决吗

$db_host = "localhost"; //Host address 
$db_name = "1111"; //Name of Database
$db_user = "111"; //Name of database user
$db_pass = "111"; //Password for database user
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);

0 个答案:

没有答案