当我尝试使用php

时间:2015-12-08 14:02:31

标签: php mysql xampp

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;
}

}

在我尝试在我的代码中运行此类后,它说我

  

致命错误:调用未定义的函数execute()   第21行的C:\ xampp \ htdocs \ poll \ models \ poll.php

我正在使用xampp并且无法理解为什么它不起作用。

2 个答案:

答案 0 :(得分:1)

修改

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="test" ng-init="testValue = 0">
  <label ng-bind="testValue | currency"></label>
  <input style="display:block;" ng-model="testValue" type="number"/>
</div>

$statement = execute();

答案 1 :(得分:0)

应该是$ statement-&gt; 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;
}
}