首页 > 解决方案 > 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

请建议如何解决这个问题。

标签: phpmysqlcodeigniter

解决方案


尝试分批运行

$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());
}

推荐阅读