php - 50000个ID签入codeigniter中的where子句
问题描述
我试过下面的查询
$arrIds = array('1'=>'1111'......'50000'=>'50000'); // 50K ids here
$this->db->select('id');
$this->db->from('mytable');
$this->db->where_in('id',$arrIds);
$query = $this->db->get();
$result = $query->result_array();
运行时出现此错误
**Oops! Something's wrong!**
Severity: Warning
Message: preg_match(): Compilation failed: regular expression is too large at offset 46343
Filename: database/DB_query_builder.php
Line Number: 2395
请建议如何解决这个问题。
解决方案
尝试分批运行
$arrIds = array('1'=>'1111'......'50000'=>'50000'); // 50K ids here
foreach (array_chunk($arrIds, 10000) as $chunkIds) {
$this->db->select('id');
$this->db->from('mytable');
$this->db->where_in('id', $chunkIds);
$query = $this->db->get();
$result = array_merge($result, $query->result_array());
}
推荐阅读
- java - 调用@Sheduled 方法后未找到“强制”的现有事务
- r - 用数据框中的值替换向量的元素
- javascript - 从字符串重新实例化自定义类
- python - 显示无法与 pyvirtualdisplay 一起使用:“XStartTimeoutError:无法在显示“:1001”上启动 X(xdpyinfo 检查失败)”
- javascript - jQuery scrollTop 仅在 DevTools 在 Edge 中打开时有效
- bash - 这个 bash 行长度限制来自哪里?
- awk - awk 比较两个文件中的两列打印结果
- android - 从另一个应用程序的活动中获取数据?
- python - Django 2.1 使用 makemigrations 创建的迁移未显示在迁移文件夹中
- html - 如何解决 HTML/CSS 中的边距问题和 div 问题?