您好我已经尝试了一些解决方案但仍然无法为我工作。 我跟着代码:
public function databaseSearch($connection,$keyword){
$test =$connection->query("SELECT * FROM courses WHERE courseKeywords LIKE %?%");
$test->bind_param("s",$keyword);
$test->execute();
return $test->get_result();
}
获得:
Call to a member function bind_param() on a non-object
这就是我所说的:
$queryRepository = new QueryRepository();
$queryRepository->checkKeyword($keyword);
$result = $queryRepository->databaseSearch($connection,$keyword);
我认为它可能是语法错误,但简单的查询也不起作用。
答案 0 :(得分:1)
我在那里发现了问题。我不得不添加私有变量:
private $courseKeywords;
然后在bind_param之后将以下行添加到databaseSearch函数:
$this->courseKeywords = $courseKeywords
“整体”课程如下:
class QueryRepository{
private $courseKeywords;
private $rowsAffected;
public function databaseSearch($connection,$courseKeywords){
$statement = $connection->prepare("SELECT * FROM courses WHERE courseKeywords like ?");
$statement->bind_param("s",$this->courseKeywords);
$this->courseKeywords = $courseKeywords;
$statement->execute();
$statement->close();
$this->rowsAffected = $connection->affected_rows;
}
public function rowsAffected(){
return $this->rowsAffected;
}
答案 1 :(得分:-1)
我认为您的查询应该像
$ test = $ connection-> query(" SELECT * FROM courses WHERE courseKeywords LIKE:s"); //假设你有参数'
希望这可以解决您的问题