使用数据库实用程序将数据从 Codeigniter 批量导出到 CSV Class
Bulk Exporting Data from Codeigniter to CSV using Database Utility Class
这是我的代码:
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 条记录。当我尝试下载 link 变成 dead.is 时,有任何其他方法可以将无限记录批量导出到 csv
。
我在设置 ini_set('max_execution_time', 0) 后测试了这段代码高达 30000;它工作正常。
除 CSV 之外的任何可以显示批量记录的 xls。
我认为 codeignatormax_execution_time
有问题
您可以使用以下代码增加它
转到文件
system/core/CodeIgniter.php
Ans 搜索 set_time_limit
您会找到以下代码。在这里你可以增加你的时间
if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
{
@set_time_limit(300);// increase according to your requirmrnt
}
// top of your controller
ini_set('max_execution_time', 0);
// Also you can increase memory
ini_set('memory_limit','2048M');
下载此 helper 并放入 system/helpers/
最后像这样创建 csv
$this->db->select('*');
$query = $this->db->get('your_table');
$this->load->helper('csv');
query_to_csv($query, TRUE, 'filename.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 条记录。当我尝试下载 link 变成 dead.is 时,有任何其他方法可以将无限记录批量导出到 csv
。
我在设置 ini_set('max_execution_time', 0) 后测试了这段代码高达 30000;它工作正常。
除 CSV 之外的任何可以显示批量记录的 xls。
我认为 codeignatormax_execution_time
有问题
您可以使用以下代码增加它
转到文件
system/core/CodeIgniter.php
Ans 搜索 set_time_limit
您会找到以下代码。在这里你可以增加你的时间
if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
{
@set_time_limit(300);// increase according to your requirmrnt
}
// top of your controller
ini_set('max_execution_time', 0);
// Also you can increase memory
ini_set('memory_limit','2048M');
下载此 helper 并放入 system/helpers/
最后像这样创建 csv
$this->db->select('*');
$query = $this->db->get('your_table');
$this->load->helper('csv');
query_to_csv($query, TRUE, 'filename.csv');