准备好的声明:调用非对象的成员函数

时间:2010-10-18 07:58:26

标签: php sql mysql prepared-statement

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很糟糕,但我无法看到错误。

2 个答案:

答案 0 :(得分:0)

您应该发布完整的错误消息。

问题是,正如Andomar所说,可能$stmt是错误而不是语句对象。

答案 1 :(得分:0)

发现我的问题。我为访问数据库而创建的用户没有适当的权限。

相关问题