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

时间:2014-02-28 01:48:19

标签: php mysql database mysqli

$stmt = $db->prepare("SELECT post_id,content,date,category_id,lp_title,lp_image,lp_canonicalUrl,lp_url,lp_desc,lp_iframe,lp_iframe_id,img_src
    FROM post_items INNER JOIN user ON post_items.user_id = user.user_id INNER JOIN photo_upload ON post_items.post_id = photo_upload.post_id
     WHERE post_items.user_id = ? AND post_items.post_id = photo_upload.post_id order by post_items.post_id desc LIMIT ?,?");


$stmt->bind_param('iii', $userid, $itemStart, $itemEnd);

我这里有3个表:user,post_items和photo_upload。在我实现photo_upload之前,一切正常。

我说错误

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

1 个答案:

答案 0 :(得分:1)

mysqli::prepare的文档提到它返回:

  

mysqli_prepare()返回一个语句对象,如果发生错误,则返回FALSE。

尝试以下方法:

$stmt = $db->prepare("SELECT post_id,content,date,category_id,lp_title,lp_image,lp_canonicalUrl,lp_url,lp_desc,lp_iframe,lp_iframe_id,img_src
    FROM post_items INNER JOIN user ON post_items.user_id = user.user_id INNER JOIN photo_upload ON post_items.post_id = photo_upload.post_id
     WHERE post_items.user_id = ? AND post_items.post_id = photo_upload.post_id order by post_items.post_id desc LIMIT ?,?");

if ($stmt !== false) {
    $stmt->bind_param('iii', $userid, $itemStart, $itemEnd);
} else {
    print_r( $db->error );
}