2014-09-12 168 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!'); 

就在您發表聲明之後。如果您收到錯誤消息,那麼您就知道問題所在。我無法從你給出的代碼中解釋爲什麼會出現這種情況,以及爲什麼它不會更快產生錯誤。

相關問題