CodeIgniter活动记录:一次加载一行 [英] CodeIgniter Active Record: Load One Row at a Time

查看:135
本文介绍了CodeIgniter活动记录:一次加载一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档中描述的正常 result()方法似乎立即加载所有记录。我的应用程序需要加载约30,000行,一次一个,将它们提交到第三方搜索索引API。显然,一次将所有内容加载到内存中并不能很好地工作(因为内存过多导致错误)。

The normal result() method described in the documentation appears to load all records immediately. My application needs to load about 30,000 rows, and one at a time, submit them to a third-party search index API. Obviously loading everything into memory at once doesn't work well (errors out because of too much memory).

所以我的问题是,如何实现传统的MySQLi API方法,其中在循环中一次加载一行?

So my question is, how can I achieve the effect of the conventional MySQLi API method, in which you load one row at a time in a loop?

推荐答案

这里是你可以做的。

while ($row = $result->_fetch_object()) {
  $data = array(
    'id'         => $row->id
    'some_value' => $row->some_field_name
  );
  // send row data to whatever api
  $this->send_data_to_api($data);
}

这时会得到一行。检查CodeIgniter源代码,你会看到他们会在执行result()方法时这样做。

This will get one row at the time. Check the CodeIgniter source code, and you will see that they will do this when you execute the result() method.

这篇关于CodeIgniter活动记录:一次加载一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆