2

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. When I try to download the link becomes dead.is there any other method to bulk export unlimited record to csv.

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

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

8
  • try creating a zip file of your csv and than download.. you can use codeigniter's encoding class check it here ellislab.com/codeigniter/user-guide/libraries/zip.html Commented Jun 9, 2015 at 6:27
  • @NishantSolanki - not working either Commented Jun 9, 2015 at 6:39
  • @kiran what you mean by dead link?? what error you get?? Commented Jun 9, 2015 at 6:46
  • @NishantSolanki - no error only blank white page Commented Jun 9, 2015 at 6:55
  • @Kiranarya have you tried limiting the data?? if thats working?? Commented Jun 9, 2015 at 7:01

2 Answers 2

1
// 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/

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');
Sign up to request clarification or add additional context in comments.

7 Comments

Upto 10 MB CSV with 24000 records my code is working fine but not more than that
Make a try with this, and let me know
dead link meaning ? try to increase memory as well
Dead link means nothing just white blank page
I increased max_execution_time and memory_limit both.but page is loading from last 4-5 minutes.I think it worked hopefully by the end of the this day i will get my CSV file
|
0

I think there is problem in max_execution_time of codeignator

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. 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
}

3 Comments

@set_time_limit(1000); @set_time_limit(10000); but still white blank page
300 means 5 minutes.. check this php.net/manual/en/function.set-time-limit.php... and if dont want to timeout the page than one should use set_time_limit(0);..
Thanks @NishantSolanki for your link am bit confuse in second or minutes now it clear

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.