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);
那里有什么不好?
答案 0 :(得分:0)
错误是因为您的类没有$DBH
字段,因此它不存在,因此它不是对象。
可能你错过了在构造函数中实例化或注入$DBH
值。