Fatal error: Uncaught Error: Call to a member function fetchAll() on bool php mvc pdo
Fatal error: Uncaught Error: Call to a member function fetchAll() on bool php mvc pdo
我尝试了以下代码,但出现错误“致命错误:调用 bool 上的成员函数 fetchAll()
这是控制器 I have try the following code but the error "Fatal error: Call to a member function fetchAll() on a non-object
这是代码`
public function __construct($id_sym,$nom_sym){
$this->id_sym=$id_sym;
$this->nom_sym=$nom_sym;
}
public function add($connexion){
$connexion->exec("insert into medicale2(nom_sym) values('".$this->nom_sym."')");
header("location:index.php?controller=symptome&action=index");
}
public function edit($connexion){
$connexion->exec("update medicale2 set nom_sym='".$this->nom_sym."'");
header("location:index.php?controller=symptome&action=index");
}
public function delete($connexion){
$connexion->exec("delete from medicale2 where id_sym='".$this->id_sym."'");
header("location:index.php?controller=symptome&action=index");
}
public function index($connexion){
$res=$connexion->query("select * from medicale2")->fetchAll(PDO::FETCH_OBJ);
return $res;
}
public function detail($connexion){
$res=$connexion->query("select * from medicale2 where id_sym='".$this->id_sym."'")->fetch(PDO::FETCH_OBJ);
return $res;
}
}`
实际上,查询不执行SQL查询。
你应该先执行它,然后再调用它的方法 'fetchAll'!
public function index($connexion){
$prepare=$connexion->prepare("select * from medicale2");
$prepare->execute();
$res=$prepare->fetchAll(PDO::FETCH_OBJ);
return $res;
}
我尝试了以下代码,但出现错误“致命错误:调用 bool 上的成员函数 fetchAll()
这是控制器 I have try the following code but the error "Fatal error: Call to a member function fetchAll() on a non-object
这是代码`
public function __construct($id_sym,$nom_sym){
$this->id_sym=$id_sym;
$this->nom_sym=$nom_sym;
}
public function add($connexion){
$connexion->exec("insert into medicale2(nom_sym) values('".$this->nom_sym."')");
header("location:index.php?controller=symptome&action=index");
}
public function edit($connexion){
$connexion->exec("update medicale2 set nom_sym='".$this->nom_sym."'");
header("location:index.php?controller=symptome&action=index");
}
public function delete($connexion){
$connexion->exec("delete from medicale2 where id_sym='".$this->id_sym."'");
header("location:index.php?controller=symptome&action=index");
}
public function index($connexion){
$res=$connexion->query("select * from medicale2")->fetchAll(PDO::FETCH_OBJ);
return $res;
}
public function detail($connexion){
$res=$connexion->query("select * from medicale2 where id_sym='".$this->id_sym."'")->fetch(PDO::FETCH_OBJ);
return $res;
}
}`
实际上,查询不执行SQL查询。 你应该先执行它,然后再调用它的方法 'fetchAll'!
public function index($connexion){
$prepare=$connexion->prepare("select * from medicale2");
$prepare->execute();
$res=$prepare->fetchAll(PDO::FETCH_OBJ);
return $res;
}