title: Export Data As CSV In CodeIgniter
body: <p>I need to export results from a MySQL query into a csv file in codeigniter.</p>
  
  <p>This is the model:</p>
  
  <pre><code>public function export_csv()
  {
  
         $this-&gt;load-&gt;dbutil();
      $this-&gt;load-&gt;helper('file');
      $this-&gt;load-&gt;helper('download');
      $delimiter = ",";
      $newline = "\r\n";
      $file_name = 'BVN_REPORTS'.date("Y-m-d h-i-s").'.csv';
      $query = 'SELECT  account_name as "Account Name",
      api_account_name as "Verified Name", 
      account_num "Account Number", 
      bvn "Bank Verification Number (BVN)", bank_name as "BANK NAME" 
      from ew_employees where bvn is not null
      ORDER BY bank_name ';
     $result = $this-&gt;db-&gt;query($query);
     $data = $this-&gt;dbutil-&gt;csv_from_result($result, $delimiter, $newline);
     if(force_download($filename, $data)){
     echo 'Done';
     }
     else {echo 'Not Done';}
      }
  </code></pre>
  
  <p>And this is the controller:</p>
  
  <pre><code>  public function get_csv()
  {
       $this-&gt;load-&gt;model('employees_model');
       $this-&gt;employees_model-&gt;export_csv();
  }
  </code></pre>
  
  <p>The result is always 'Not Done'...how can i force a csv download of the query results.Thanks</p>