准备好的语句:调用非对象上的成员函数
public function endGame($result) {
$sql = "UPDATE games SET result = ? WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->bind_param("si", $result, $this->currentGame);//Error here
$stmt->execute();
$stmt->close();
}
mysql> describe games;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(12) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
| date_played | datetime | NO | | NULL | |
| difficulty | tinyint(4) | YES | | NULL | |
| result | varchar(20) | NO | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
Fatal error: Call to a member function bind_param() on a non-object
我知道此设置中的非对象错误可能意味着我的 sql 错误,但我无法看到该错误。
public function endGame($result) {
$sql = "UPDATE games SET result = ? WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->bind_param("si", $result, $this->currentGame);//Error here
$stmt->execute();
$stmt->close();
}
mysql> describe games;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(12) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
| date_played | datetime | NO | | NULL | |
| difficulty | tinyint(4) | YES | | NULL | |
| result | varchar(20) | NO | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
Fatal error: Call to a member function bind_param() on a non-object
I know a non-object error in this setup probably means my sql is bad, but I am having trouble seeing the error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该发布完整的错误消息。
问题是,正如 Andomar 所说,可能
$stmt
是一个错误而不是语句对象。You should post the full error message.
The problem is, as Andomar said, probably that
$stmt
is an error instead of a statement object.发现我的问题了。我创建的用于访问数据库的用户没有适当的权限。
Found my problem. The user I created to access the database didn't have proper permissions.