class poll
{
private $db;
public function __construct($dbConnection)
{
$this->db = $dbConnection;
}
public function getPollData(){
$sql = "SELECT poll_question, yes, no FROM poll WHERE poll_id=1";
$statement = $this->db->prepare($sql);
$statement = execute();
$pollData = $statement->fetchObject();
return $pollData;
}
}
当我尝试在我的代码中运行该类后,它说我
致命错误:在第21行的C:\ xampp \ htdocs \ poll \ models \ poll.php中调用未定义的函数execute()
我正在使用xampp,无法理解为什么它不起作用。
应该是$ statement-> execute();
class poll
{
private $db;
public function __construct($dbConnection)
{
$this->db = $dbConnection;
}
public function getPollData(){
$sql = "SELECT poll_question, yes, no FROM poll WHERE poll_id=1";
$statement = $this->db->prepare($sql);
$statement = $statement->execute(); // You miss the $statement var
$pollData = $statement->fetchObject();
return $pollData;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句