使用数据库实用程序类从Codeignitor批量导出数据到CSV [英] Bulk Exporting Data from Codeignitor to CSV using Database Utility Class

查看:203
本文介绍了使用数据库实用程序类从Codeignitor批量导出数据到CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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); 

}

过去30天内共有64,145条记录。当我尝试下载链接变得死亡时,有任何其他方法可以批量导出无限制的记录到 csv

There is 64,145 Records in last 30 days. When I try to download the link becomes dead.is there any other method to bulk export unlimited record to csv.

在设置ini_set('max_execution_time',0)后,我测试了这个代码,最多可以达到30000。它的工作正常。

I tested this code upto 30000 after setting ini_set('max_execution_time', 0);It works fine.

除了可以显示批量记录的xls之外的其他任何东西帮帮我。

Anything other than CSV like xls which can show bulk records.Any help.

谢谢。

推荐答案

// top of your controller
ini_set('max_execution_time', 0);

// Also you can increase memory
ini_set('memory_limit','2048M');

下载此帮助,并放在 system / helpers /

,最后创建这样的csv

and finally create csv like this

$this->db->select('*'); 
$query = $this->db->get('your_table');
$this->load->helper('csv');
query_to_csv($query, TRUE, 'filename.csv');

这篇关于使用数据库实用程序类从Codeignitor批量导出数据到CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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