2014-09-12 170 views
0

我已经看到与此类似的非常类似的错误问题,但是我似乎仍然无法解决问题,所以很抱歉如果这可能是重复的。致命错误:调用非对象的成员函数bind_param()

反正这里是代码:

/** 
* 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

$ stmt-> bind_param(“s”,$ userId);这应该是“我”我相信,因为id是整数不是字符串 – 2014-09-12 12:09:31

+0

你可能需要添加关闭类,所以我们可以看到你是如何设置属性conn – 2014-09-12 12:09:40

+0

尝试$ stmt-> bind_param(“我”,$ userId) ; ...仍然不能正常工作 – AbhiCool 2014-09-12 12:13:47

回答

0

你的错误是:

Fatal error: Call to a member function bind_param() on a non-object

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

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

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

相关问题