Performance on query database with Codeigniter -
i'm looking in method best performance on getting data database query, main problem doing next example of query give me error message: preg_match(): compilation failed: regular expression large @ offset 44123
can resolved adding pcre library backtracking limit options
php,ini
.
it resolve issue on server/hosting not in others if used many users.
my query quite simple:
i have array of 5k of rows:
$data = array( array('product_id' => 1), array('product_id' => 2), ++ 4998 );
i need foreach product id , ask database , insert data if exist if not return me product_id doesn't exist, store in array.
//controller method function test(){ foreach($data $row){ $exist[] = $this->model->askdatabase($row->product_id); } if($exist){ $getexistents = $exist; } if(!$getexistents == null){ //and here error produced "regular expression large" $this->db->select('*')->from('products_2')->where_in('product_id', $getexistents)-get(); } } //model method function askdatabase($product_id){ $exist = $this->db->select('id')->from('products')->where('product_id', $row->product_id)-get(); if($exist->num_rows() > 0 ){ return $exist->row()->id; }else{ return false; } }
is better execute foreach loop again 'where' condition instead where_in ? or there method can better performance on executing query?
any appreciated !
Comments
Post a Comment