致命错误:在非对象上调用成员函数bind_param()

时间:2014-09-12 12:07:38

标签: php pdo

我见过类似的问题,但是我似乎仍无法解决问题,所以如果这可能是重复的话,我很抱歉。

无论如何这里是代码:

/**
 * 8.This method is used to get no of pending bets.
 */
public function noOfPendingBets($userId){
    $res = array();

    $stmt = $this->conn->prepare("select bet_id from user_bets where user_id=?");
    echo $userId;
    $stmt->bind_param("s", $userId);

    $stmt->execute();

    $stmt->bind_result($bet_id);
    $num_row=0;
    $stmt->fetch();
    echo "bet_id:".$bet_id."<br>";

    $sumBets=$this->abc($bet_id);
    $num_row = $num_row+$sumBets;



    $stmt->close();
    return $num_row;    

 }

public function abc($bet_id)
{
    $stmt = $this->conn->prepare("select u.user_id from user u inner join bets b on u.user_id=b.creator_id  and b.bet_id=? and b.correct_option is null");

    $stmt->bind_param("i", $bet_id);

    $stmt->execute();

    $stmt->store_result();
    echo "no of rows:".$stmt->num_rows;
    return $stmt->num_rows;
    $stmt->close();
}

1 个答案:

答案 0 :(得分:0)

您的错误是:

  

致命错误:在非对象

上调用成员函数bind_param()

因此,bind_pamam()的父对象是非对象。那应该是你的$stmt变量。所以$stmt不是一个对象。加入此测试:

if (!is_object($stmt)) die('ERROR: My statement is not an object!');

在你发表声明之后。如果您收到错误消息,那么您就知道问题所在。我无法从您给出的代码中解释为什么会发生这种情况,以及为什么它不会更快地产生错误。