• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fatal memory error

#1
Sad 
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;     

    }
Reply

#2
Try this to pinpoint the problem for us.

PHP Code:
// try this before your query to see if you need to increase
// your php.ini memory_limit

ini_set('memory_limit''1024M'); // or you could use 1G

// do a backtrace to see if there are other problems
// add this before your query to see if the problem is there

var_dump debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); 

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 )
Reply

#3
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
Reply

#4
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 )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.