Fatal memory error |
When i run this query for API. I am getting allowed memory size of 134217728 bytes exhausted.
Query is public function categories_with_products(){ $this->db->select('category_id,category_name,parent_category'); $this->db->from('categories_info'); $this->db->where('parent_category', 1); $parent = $this->db->get(); $categories = $parent->result(); $i=0; foreach($categories as $p_cat){ $categories[$i]->sub_categories = $this->sub_categories_with_products($p_cat->category_id); $i++; } return $categories; /* echo json_encode ( array('cat'=>$categories, ));*/ } public function sub_categories_with_products($id){ $this->db->select('category_id,category_name,parent_category'); $this->db->from('categories_info'); $this->db->where('parent_category', $id); $child = $this->db->get(); $categories = $child->result(); $i=0; foreach($categories as $p_cat){ $categories[$i]->sub_category = $this->sub_categories_products($p_cat->category_id); $i++; } return $categories; } public function sub_categories_products($id){ $this->db->select('product_name,category_id'); $this->db->from('products_info'); $this->db->where('category_id', $id); $child = $this->db->get(); $categories = $child->result(); $i=0; foreach($categories as $p_cat){ $categories[$i]->products = $this->sub_categories_products($p_cat->category_id); $i++; } return $categories; }
Try this to pinpoint the problem for us.
PHP Code: // try this before your query to see if you need to increase Let us know what you find out. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
i have used the memory increase at
AS $old = ini_set('memory_limit', '8192M'); at top of Model & controller page, AND THIS where should i add this before which query ? var_dump debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); categories_info Table @ https://ibb.co/QDpykdD products_info Table @ https://ibb.co/5cc3ZSM
First try setting the memory_limit, this can also be done in php.ini file.
try it before and after your queries to see if there is some other problem. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |