简体   繁体   English

CodeIgniter-内存中的result_array

[英]CodeIgniter - result_array in memory

I don't know if this is a valid programming question. 我不知道这是否是一个有效的编程问题。 But there is something troubling my mind about CodeIgniter. 但是我对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. 我正在为项目使用CodeIgniter和MS SQL。 I am retrieving sales data that is 20M+ rows. 我正在检索超过2000万行的销售数据。 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? 现在,我在想,CodeIgniter的result_array()函数是否将所有结果存储到内存中? 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? 假设我在内存中加载了前100行,然后删除了这100行,然后又加载了100行? So PHP would not fill my memory with results. 因此,PHP不会用结果填充我的记忆。

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 我正在使用jQwidgets透视网格

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. 或者,也许您可​​以建议我可以采用哪些其他选项或设计来处理PHP中的大数据。

Hope I explained myself clearly. 希望我能清楚地解释自己。 Thankyou very much. 非常感谢你。 I would appreciate all your suggestions. 非常感谢您的所有建议。

I believe you are looking for the little-known unbuffered_row function: 我相信您正在寻找鲜为人知的unbuffered_row函数:

$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. 此方法返回单个结果行,而不像row()那样预取整个结果在内存中。 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 https://www.codeigniter.com/userguide3/database/results.html

You can also get an array: 您还可以获得一个数组:

$query->unbuffered_row('array');        // associative array

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM