当我仅通过关键字搜索时,该搜索引擎应该会给我输出。当我仅搜索状态时,还应该在给出状态和关键字时进行搜索。如果未给出任何内容,则应获取表中的所有属性,但这会给我一个错误:
致命错误:未捕获错误:调用成员函数bindValue() C:\ xampp \ htdocs \ accommoport \ sch \ search.php:72中的字符串:堆栈跟踪: 0)
如何完成此操作?
$keyword= $_GET["keyword"];
$stmt_search = "SELECT * FROM houses WHERE
(property_city LIKE :param
OR property_state LIKE :param
OR property_address LIKE :param
OR property_name LIKE :param)
-- AND property_status LIKE :status
";
$stmt_search->bindValue(':param', '%'.$keyword.'%');
if($_GET['search_status']!='')
{
$status =$_GET["search_status"];
$stmt_search .= "AND property_status LIKE :pstatus";
$stmt_search->bindValue(':pstatus', $status);
}
$stmt=$conn->prepare($stmt_search);
$stmt->execute();
if($stmt->rowCount() > 0){
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
# code...
?>
答案 0 :(得分:0)
您正在尝试对字符串执行方法。绑定参数的方式是:
$sth = $connection->prepare("SELECT * FROM houses WHERE property_city LIKE :param");
$sth->bindParam(':param','%'.$keyword.'%');
$sth->execute();