鍍金池/ 問答/PHP/ laravel下載數(shù)據(jù)關聯(lián)模型數(shù)據(jù)多超出mysql占位數(shù)?

laravel下載數(shù)據(jù)關聯(lián)模型數(shù)據(jù)多超出mysql占位數(shù)?

1、查詢用戶列表,初始換關聯(lián)訂單表,但是用戶太多,導致mysql占位符過了,報mysql錯誤。

2、User::with('order')->get()

報錯:General error: 1390 Prepared statement contains too many placeholders

select * from order where user_id in (xxx,xxx , ......)
因為后續(xù)需要循環(huán)處理訂單相關聯(lián)的數(shù)據(jù)。
foreach ($user as $v) {

$order_list = $v->order;
$temp_test = [];
if (count($order_list) > 0) {
    foreach ($order_list as $ov) {
        $temp_test[] = $ov->order_id;
    }
}
$data = [
    'user_id' => $v->user_id,
    'order_id' => implod(',', $temp_test)
];
echo $this->downExcel($data);

}

回答
編輯回答
壞脾滊

使用chunk即可。

2018年6月21日 05:32