7

I am looking at this.

I have queries that return up to 10,000 rows and usually fills up the memory

I am currently doing:

$this->db->get()->result_array();

Is there a way to not load all of the data into memory and use some sort of cursor? It seems result and result array are both arrays. (one is array of objects other is an array of arrays)

3
  • 3
    You can use Pagination with limit, i.e. $query = $this->db->get('mytable', 10, 20);. Commented Jan 7, 2013 at 0:00
  • I was hoping not to do pagination, but I think I will have to do that for large queries in the future. Commented Jan 7, 2013 at 2:28
  • 2
    Can't you just use the limit clause? Commented Jan 7, 2013 at 3:41

2 Answers 2

7

If you are using Active Record, which I would personally recommend, limit() should achieve what you are looking for.

$this->db->limit();

Can also use in this way, slightly easier and less lines of code:

$query = $this->db->get('Table_Name', 50); //syntax db->get('Table',limit_val);
return $query->result();

Also can return a limit with an offset:

$this->db->limit(10, 20); // Second parameter lets you set a result offset

Link for more help on Active Record Query's https://www.codeigniter.com/userguide2/database/active_record.html#select

Sign up to request clarification or add additional context in comments.

Comments

2

Mysql offset is the pointer you are looking for. You can use it like:

    $this->db->get(tableName,10,20);

The second parameter and the third one help you to set limit and offset .

Here are more details

Comments

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.