Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 770739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:32:43+00:00 2026-05-14T18:32:43+00:00

i’ve run into a curious problem with codeigniter’s odbc driver. i’m connecting from a

  • 0

i’ve run into a curious problem with codeigniter’s odbc driver.
i’m connecting from a linux machine to an MSSQL 2008 machine using FreeTDS.

while i get that the ‘num_rows’ function always returns -1, and that is fully a database/driver issue – for some reason when i try to create a ->result(), the whole application crashes (error 500, sometimes just a blank page), if i’m lucky, i get an error message informing me that the application died because it tried to allocated 2 terrabytes of memory(!).

This happens irregularly, ie: every few refreshes. sometimes it runs fine, sometimes the page returns error 500 and sometimes it gives the memory allocation error – in any case it’s not really something that can be reproduced with percision, and the queries are SUPER simple.

ideas anyone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:32:43+00:00Added an answer on May 14, 2026 at 6:32 pm

    Ha ha, this happend to me too! And I’ve complained to the devs about it, and they ignored me.

    When you call result(), it will loop through every single possible result, and store the record into a massive internal array. See system/database/DB_result.php while loop at the end of result_object() and result_array()

    There are three ways of fixing it.

    The easy way:

    LIMIT (or TOP in MSSQL) your results in the SQL query.

    SELECT TOP(100) * FROM Table
    

    The UPDATED unbuffered way:

    Use the unbuffered_row() function that was introduced 2 years after this question was asked.

    $query = $this->db->query($sql);
    // not $query->result() because that loads everything into an internal array.
    // and not $query->first_row() because it does the same thing (as of 2013-04-02)
    while ($record = $query->unbuffered_row('array')) { 
        // code...
    }
    

    The hard way:

    Use a proper result object that uses PHP5 iterators (that the devs don’t like because it excludes php4). Slap something like this in your DB_result.php file:

    -class CI_DB_result {
    +class CI_DB_result implements Iterator {
    
        var $conn_id        = NULL;
        var $result_id      = NULL;
        var $result_array   = array();
        var $result_object  = array();
    -   var $current_row    = 0;
    +   var $current_row    = -1;
        var $num_rows       = 0;
        var $row_data       = NULL;
    +   var $valid          = FALSE;
    
    
        /**
        function _fetch_assoc() { return array(); } 
        function _fetch_object() { return array(); }
    
    +   /**
    +    * Iterator implemented functions
    +    * http://us2.php.net/manual/en/class.iterator.php
    +    */
    +   
    +   /**
    +    * Rewind the database back to the first record
    +    *
    +    */
    +   function rewind()
    +   {
    +       if ($this->result_id !== FALSE AND $this->num_rows() != 0) {
    +           $this->_data_seek(0);
    +           $this->valid = TRUE;
    +           $this->current_row = -1;
    +       }
    +   }
    +   
    +   /**
    +    * Return the current row record.
    +    *
    +    */
    +   function current()
    +   {
    +       if ($this->current_row == -1) {
    +           $this->next();
    +       }
    +       return $this->row_data;
    +   }
    +   
    +   /**
    +    * The current row number from the result
    +    *
    +    */
    +   function key()
    +   {
    +       return $this->current_row;
    +   }
    +   
    +   /**
    +    * Go to the next result.
    +    *
    +    */
    +   function next()
    +   {
    +       $this->row_data = $this->_fetch_object();
    +       if ($this->row_data) {
    +           $this->current_row++;
    +           if (!$this->valid)
    +               $this->valid = TRUE;
    +           return TRUE;
    +       } else {
    +           $this->valid = FALSE;
    +           return FALSE;
    +       }
    +   }
    +   
    +   /**
    +    * Is the current_row really a record?
    +    *
    +    */
    +   function valid()
    +   {
    +       return $this->valid;
    +   }
    +   
     }
     // END DB_result class
    

    Then to use it, instead of calling $query->result() you use just the object without the ->result() on the end like $query. And all the internal CI stuff still works with result().

    $query = $this->db->query($sql);
    foreach ($query as $record) { // not $query->result() because that loads everything into an internal array.
        // code...
    }
    

    By the way, my Iterator code working with their code has some logic problems with the whole -1 thing, so don’t use both $query->result() and $query on the same object. If someone wants to fix that, you are awesome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 431k
  • Answers 431k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Create a new VS macro and add this code :… May 15, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer You will not be happy with the solution of using… May 15, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer What I did to get around this was create a… May 15, 2026 at 2:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.