MySqli problem: memory exhausted and can't edit php.ini

edited January 2015 in Modules
Hi, I am having the error
"Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in codeigniter/database/drivers/mysqli/mysqli_result.php on line 152"

The line 152: return mysqli_fetch_assoc($this->result_id);

and I can't edit memory_limit within php.ini because I don't have permission on the server.

The table I am trying to access has more than 600.000 rows.

In the function list_items of the class Songs_model file I filter the select
$this->db->select('songs.id,songs.title', FALSE);
So It only brings two columns.

Any idea how can I avoid this error?
Thank you.

Comments

  • edited 5:56PM
    What view is this error happening on? The list view? If so, what does your module model's list_items method look like (if you added one)?
  • edited 5:56PM
    It all happens in my songs_model.php file.The class looks like this:
    class Songs_model extends Base_module_model { function __construct() { parent::__construct('songs'); } function list_items($limit = 10, $offset = NULL, $col = 'title', $order = 'ASC') { $this->db->select('songs.id,songs.title', FALSE); $data = parent::list_items($limit, $offset, $col, $order); return $data; } function form_fields($values = array()) { $fields = parent::form_fields($values); return $fields; } } class Song_model extends Data_record { }
  • edited 5:56PM
    There should be a 5th parameter called $just_count (unless you are on a pre-1.0 version of FUEL), that should fix your problem. Try this:
    function list_items($limit = 10, $offset = NULL, $col = 'title', $order = 'ASC', $just_count = FALSE) { $this->db->select('songs.id,songs.title', FALSE); $data = parent::list_items($limit, $offset, $col, $order, $just_count); return $data; }
  • edited 5:56PM
    Hello thank you, that solved the problem and the list appear on screen. BUT when I click on a item in the list to edit, it crashes again the same:

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 30 bytes) in /fuel/codeigniter/database/drivers/mysqli/mysqli_result.php on line 152

    Is there a parameter or something that I need to put in a function before the "edit screen" loads?
  • edited 5:56PM
    That error may be due to the "get_others" method on the model that returns a drop down of all the other records for easy navigation. Try adding this to your model:
    public function get_others($display_field, $id = NULL, $val_field = NULL) { return array(); }
  • edited 5:56PM
    That almost solved the problem. After adding those lines, the screen goes white (but does not show the memory error).
    So I commented the lines of the $foreign_keys and then it worked again but of course I loose the foreign keys functionality. One of the foreign keys tries to load in the combo a huge number of rows.
    Is there an easy way to load the foreign keys "on demand"? or for example load only 100 and then load via ajax?
    Thank you.
  • edited 5:56PM
    You can add a where and order parameter to the foreign keys, however, it doesn't have a limit parameter:
    public foreign_keys = array('my_foreign_key' => array('my_model', 'where' => 'type = "my_type"', 'order' => 'desc');
    To add a limit, you can use active record before calling the form_fields parent like so:
    public function form_fields($values = array(), $related = array()) { $CI =& get_instance(); $CI->load->model('my_foreign_model'); $CI->my_foreign_model->db()->limit(10); $fields = parent::form_fields($values, $related); .... return $fields; }

    Or, you could override the options_list method on your foreign model. By default, the options for the field are generated by $CI->$model->options_list(NULL, NULL, $where, $order);
Sign In or Register to comment.