MySqli problem: memory exhausted and can't edit php.ini
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
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 { }
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; }
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?
public function get_others($display_field, $id = NULL, $val_field = NULL) { return array(); }
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.
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);