0
我想從MySQL數據庫收集一些信息,並遇到一些問題。我可以獨立執行,要麼是我兩個查詢的,但是當我嘗試執行他們兩個我的代碼失敗,出現錯誤Call to a member function bind_param() on a non-object in /api/boxes.php on line 20
,其中第20行是$queryFacet = $db->prepare("SELECT item_name FROM kf_facet_items WHERE id IN (SELECT facet_value_id FROM kf_box_data WHERE box_id = ?)");
執行多個查詢時mysqli失敗
這裏是我的代碼:
$query = $db->prepare("SELECT DISTINCT b.id, b.ownerID, b.transactionID, b.post_date, b.description FROM kf_boxes b JOIN kf_box_data d ON b.id = d.box_id");
$query->execute();
$query->bind_result($id, $owner, $transactionID, $post_date, $description);
while ($query->fetch()) {
$result['id'] = $id;
$result['transaction'] = $transactionID;
$result['post_date'] = $post_date;
$result['description'] = $description;
$queryFacet = $db->prepare("SELECT item_name FROM kf_facet_items WHERE id IN (SELECT facet_value_id FROM kf_box_data WHERE box_id = ?)");
$queryFacet->bind_param('s',$id);
$queryFacet->execute();
$queryFacet->bind_result($item_name);
while ($queryFacet->fetch()) {
$facets['name'] = $item_name;
$result['facets'] = $facets;
}
$output[] = $result;
}
任何人有任何想法什麼是造成這一點,更重要的是,如何解決它?
你沒有做任何錯誤檢查,所以你不會明白爲什麼查詢失敗。 –
@popnoodles當它自己執行該查詢時,這不會造成問題嗎?它沒有。 – Jeremy1026
http://stackoverflow.com/questions/6659882/call-to-a-member-function-bind-param-on-a-non-object-unable-to-solve-despite 第5個結果谷歌搜索 – Popnoodles