title: Allowed memory size exceeding 256mb on simple mysql select query
body: <p>EDIT: For anyone finding this at a later date CI will use alot of memory in these sorts of circumstances since it will create an object for every row (using result_array() doesn't seem much better), so the best bet is just to use PHP's built in mysql functions. If you're using MYSQLI you can access the connection link like so:</p>
  
  <pre><code>$this-&gt;db-&gt;conn_id
  </code></pre>
  
  <p>I'm trying to run a script through the command line (testing for what will be a cronjob), what the script does is irrelevant since it is failing at the first select and doesn't get any further.</p>
  
  <p>I am using Codeigniter 2.0.3.</p>
  
  <p>My table looks like this:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `graphic_files` (
    `graphic_file_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `graphic_file_style_id` tinyint(2) unsigned NOT NULL,
    `graphic_file_fm_id` bigint(20) unsigned DEFAULT NULL,
    `graphic_file_config_line` varchar(255) NOT NULL,
    `graphic_file_config_line_hash` varchar(32) NOT NULL,
    `graphic_file_location` varchar(255) DEFAULT NULL,
    `graphic_file_pack_id` int(10) unsigned NOT NULL,
    `graphic_file_enabled` tinyint(1) NOT NULL,
    `graphic_file_alternative` tinyint(1) NOT NULL,
    `graphic_file_version` decimal(4,2) NOT NULL,
    `graphic_file_time_added` int(11) unsigned NOT NULL,
    `graphic_file_time_modified` int(11) unsigned NOT NULL,
    `graphic_file_size` int(11) unsigned NOT NULL,
    PRIMARY KEY (`graphic_file_id`),
    KEY `graphic_file_style_id` (`graphic_file_style_id`),
    KEY `graphic_file_fm_id` (`graphic_file_fm_id`),
    KEY `graphic_file_config_line_hash` (`graphic_file_config_line_hash`),
    KEY `graphic_file_pack_id` (`graphic_file_pack_id`),
    KEY `graphic_file_enabled` (`graphic_file_enabled`),
    KEY `graphic_file_version` (`graphic_file_version`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=240752 ;
  </code></pre>
  
  <p>There are 240,000 rows.</p>
  
  <p>I am trying to select around 120,000 of them with this query:</p>
  
  <pre><code>SELECT * FROM graphic_files WHERE graphic_file_enabled = 0 AND graphic_file_style_id = 5
  </code></pre>
  
  <p>But I get an allowed memory size error like so:</p>
  
  <blockquote>
    <p>Allowed memory size of 268435456 bytes exhausted (tried to allocate 92
    bytes) in
    xxx/codeigniter_2.0.3/database/drivers/mysqli/mysqli_result.php on
    line 167</p>
  </blockquote>
  
  <p>I realise the simple answer is that i'm out of memory, but this seems ridiculous for simply doing a select query, especially with a high allowed memory size of 256mb.</p>
  
  <p>Can anybody suggest a reason for this? Could it be to do with codeigniter and the way it builds the results object?</p>