这是我的代码:
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
。
我在设置 ini_set('max_execution_time', 0) 后测试了这段代码高达 30000;它工作正常。
除了 CSV 之外的任何东西,比如可以显示批量记录的 xls。
最佳答案
// 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');
关于php - 使用数据库实用程序类将数据从 Codeigniter 批量导出到 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30724404/