[英]Bulk Exporting Data from Codeigniter to CSV using Database Utility Class
Here is my code:这是我的代码:
function export_csv()
{
$st = $this->input->get('st'); //Start Date
$en = $this->input->get('en'); //End Date
$sTable = 'TABLE_NAME';
$this->load->dbutil();
$aColumns = array('tempdisplayid AS ucid','uui','campaign_name','location','caller_id','skill','calltime','answertime','TIMEDIFF(answertime,calltime) as timetoanswer','endtime','talktime','duration','fallback_rule','dialed_number','type','agent','agent_did','disposition','status','hangup_by','transfer','transfer_to','comments','dial_status','customer_status','agent_status','audio','AgentStatus','CustomerStatus','user_response');
$this->db->select('SQL_CALC_FOUND_ROWS '.str_replace(' , ', ' ', implode(', ', $aColumns)), false);
$query = $this->db->get_where($sTable, array('date(calltime) >=' =>$st,'date(calltime) <=' =>$en));
$new_report = $this->dbutil->csv_from_result($query);
write_file('/csv/records-'.$st.'to'.$en.'.csv', $new_report);
$this->load->helper('download');
force_download('records-'.$st.'to'.$en.'.csv', $new_report);
}
There is 64,145 Records in last 30 days.过去 30 天内有 64,145 条记录。 When I try to download the link becomes dead.is there any other method to bulk export unlimited record to csv
.当我尝试下载链接时,链接失效了。有没有其他方法可以将无限记录批量导出到csv
。
I tested this code upto 30000 after setting ini_set('max_execution_time', 0);It works fine.在设置 ini_set('max_execution_time', 0); 后,我将此代码测试到 30000;它工作正常。
Anything other than CSV like xls which can show bulk records.除了 CSV 之外的任何东西,比如 xls 可以显示批量记录。
// top of your controller
ini_set('max_execution_time', 0);
// Also you can increase memory
ini_set('memory_limit','2048M');
Download this helper and place in system/helpers/
下载这个助手并放置在system/helpers/
and finally create csv like this最后像这样创建 csv
$this->db->select('*');
$query = $this->db->get('your_table');
$this->load->helper('csv');
query_to_csv($query, TRUE, 'filename.csv');
I think there is problem in max_execution_time
of codeignator我认为 codeignator 的max_execution_time
有问题
You can increase it by using below code您可以使用以下代码增加它
Go to the file转到文件
system/core/CodeIgniter.php
Ans search for set_time_limit
you find below code. Ans 搜索set_time_limit
你在下面的代码中找到。 Here you can increse your time在这里你可以增加你的时间
if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
{
@set_time_limit(300);// increase according to your requirmrnt
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.