我正在尝试从 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 = ?)");
这是我的代码:
$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;
}
任何人对造成这种情况的原因有任何想法,更重要的是,如何解决它?