0
class Authorization {
    public $vk_id;
    public $eu_name;
    public $eu_society;
    public $eu_notes;
    public $eu_want_team;
    public $query;

    public function __construct() {
        $this->vk_id = $_POST['vk_id'];
        $this->eu_name = $_POST['eu_name'];
        $this->eu_society = $_POST['eu_society'];
        $this->eu_notes = $_POST['eu_notes'];
        $this->eu_want_team = $_POST['eu_want_team'];
    }

    function query($query) {
        $this->query = $query;
        $this->STH = $this->DBH->prepare($this->query);
        $this->STH->execute();
        $this->STH->setFetchMode(PDO::FETCH_ASSOC); 
    }
}
$auth = new Authorization();
$auth->query("INSERT INTO users (vk_id, eu_name, eu_society, eu_want_team, eu_notes) VALUES ($auth->vk_id, $auth->eu_name, $auth->eu_society, $auth->eu_want_team, $auth->eu_notes);");

它说 - :Call to a member function prepare() on a non-object line 21

line 21 is         $this->STH = $this->DBH->prepare($this->query);

那里有什么不好?

4

1 回答 1

0

错误是因为你的类没有$DBH字段,所以它不存在,所以它是非对象。

可能您错过了在构造函数中实例化或注入$DBH值。

于 2013-08-19T15:16:43.213 回答