当我尝试将 mysql 连接到 php 时,我的 XAMPP 服务器 returns 出错
My XAMPP server returns error when I try to connect mysql with php
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;
}
}
在我尝试 运行 这个 class 在我的代码中它说我
Fatal error: Call to undefined function execute() in
C:\xampp\htdocs\poll\models\poll.php on line 21
我正在使用 xampp,不明白为什么它不起作用。
修改
$statement = execute();
到
$statement = $statement->execute();
应该是$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;
}
}
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;
}
}
在我尝试 运行 这个 class 在我的代码中它说我
Fatal error: Call to undefined function execute() in C:\xampp\htdocs\poll\models\poll.php on line 21
我正在使用 xampp,不明白为什么它不起作用。
修改
$statement = execute();
到
$statement = $statement->execute();
应该是$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;
}
}