【发布时间】:2018-08-11 06:42:15
【问题描述】:
我有一个大型数据库,我获取了客户端 ID,并尝试将这些 ID 用于下一个查询。 我尝试只查询 1 次,而不是尝试查询超过 1000 次。
这是我的查询:
$query_inv_packs_for_date_range = "SELECT invid, packid, clientid,
date_range_start, date_range_end, value FROM inv_packs WHERE clientid
IN(implode(',', $in))";
然后我尝试通过解包函数参数中的数组来绑定参数。
if($stmt = mysqli_prepare($connection, $query_inv_packs_for_date_range)){
mysqli_stmt_bind_param($stmt, $types, ...$uniqueIds);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $invoice_id, $pack_id, $client_id_from_inv_pack_table, $date_range_start, $date_range_end, $value);
while(mysqli_stmt_fetch($stmt)){
$invoice_packs_table_data[$inv_pack_count]['invoiceID'] = $invoice_id;
$invoice_packs_table_data[$inv_pack_count]['packID'] = $pack_id;
$invoice_packs_table_data[$inv_pack_count]['clientID'] = $client_id_from_inv_pack_table;
$invoice_packs_table_data[$inv_pack_count]['date_range_start'] = $date_range_start;
$invoice_packs_table_data[$inv_pack_count]['date_range_end'] = $date_range_end;
$invoice_packs_table_data[$inv_pack_count]['value'] = $value;
$inv_pack_count++;
// get date ranges, and create variables that are going to be outputted immediately at the end of all calculations
// maybe not... just put them all in the array
}
$stmt->close();
}
我怎样才能让这个查询工作。
$in
$in = 问号数组,效果很好,$uniqueids 有超过 1,000 个代表 ID 的唯一数字。
【问题讨论】:
-
我不认为它是重复的,我想弄清楚如何在我的查询调用中使用 implode 函数,然后使用 '...' 绑定参数
-
如果不是重复的,它可能会帮助您简化“动态绑定”情况,因为您不可能在
mysqli_stmt_bind_param函数调用中输入一千个不同的变量名,是吗?使用call_user_func_array会有所帮助。
标签: php mysql arrays in-clause