1
我需要將結果從MySQL查詢導出到codeigniter中的csv文件中。將數據導出爲CSV在CodeIgniter中
這是模型:
public function export_csv()
{
$this->load->dbutil();
$this->load->helper('file');
$this->load->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->db->query($query);
$data = $this->dbutil->csv_from_result($result, $delimiter, $newline);
if(force_download($filename, $data)){
echo 'Done';
}
else {echo 'Not Done';}
}
這是控制器:
public function get_csv()
{
$this->load->model('employees_model');
$this->employees_model->export_csv();
}
的結果總是「未完成」 ......我怎樣才能強制查詢的CSV下載結果。謝謝
確定文件被加載? –
該文件應該動態創建並填充查詢結果 – ewom2468
檢查手動文件是否創建 –