1390使用Laravel 5.6,Prepared语句包含太多占位符

时间:2018-10-14 10:10:20

标签: mysql laravel eloquent

遇到以下错误

SQLSTATE [HY000]:常规错误:1390已准备好的语句包含太多占位符

我的查询已归因于表中的数据

SELECT
  *
FROM
  table
WHERE col1 = 'some-val'
  AND col2 NOT IN ('va1', 'val2', 80k values... )

我正在使用Laravel 5.6

$data_will_be_skipped = OtherModel::select('code')
        ->where('col1', 0)
        ->orWhere('col2', 1)
        ->groupBy('col3')
        ->pluck('col3')->toArray();

$ data_will_be_skipped现在大约 80k 个数组

Model::where('col1', 'some-val')->whereNotIn('col2', $data_will_be_skipped)->get();

1 个答案:

答案 0 :(得分:1)

MySQL在准备好的语句中最多只能有65,535个参数。

改为使用子查询:

$data_will_be_skipped = OtherModel::select('col3')
    ->where('col1', 0)
    ->orWhere('col2', 1);
Model::where('col1', 'some-val')
    ->whereNotIn('col2', $data_will_be_skipped)
    ->get();