0

I don't know if this is a valid programming question. But there is something troubling my mind about CodeIgniter. Hope you guys with years of experience and wisdom can guide me.

Here is my story,

I am using CodeIgniter and MS SQL for a project. I am retrieving sales data that is 20M+ rows. Now, I managed to reduce the result by creating aggregated data and store in in the table. Still I get the out of memory error.

Now, I am thinking, does CodeIgniter's result_array() function store all the result to the memory? Am I right with this assumption?

If yes, can I load it instead in chunks? let's say I load top 100 rows in memory, and then delete that 100 rows, and then load another 100 rows? So PHP would not fill my memory with results.

By the way, I already use pager for the detailed data. This question is needed for a specific purpose. I want to show a summary report. I am using jQwidgets Pivot Grid

I don't know if that makes sense. But that is what I am thinking. I want to understand what is happening. Or maybe you can suggest what other options or design I can make to handle large data in PHP.

Hope I explained myself clearly. Thankyou very much. I would appreciate all your suggestions.

1 Answer 1

3

I believe you are looking for the little-known unbuffered_row function:

$query = $this->db->query("YOUR QUERY");

while ($row = $query->unbuffered_row())
{
        echo $row->title;
        echo $row->name;
        echo $row->body;
}

This method returns a single result row without prefetching the whole result in memory as row() does. If your query has more than one row, it returns the current row and moves the internal data pointer ahead.

https://www.codeigniter.com/userguide3/database/results.html

You can also get an array:

$query->unbuffered_row('array');        // associative array
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Alex, thanks for the response. I will take a look and try to make it work in my project. I'll make update once I have findings. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.