Last active
December 25, 2015 04:39
-
-
Save Kcko/6918548 to your computer and use it in GitHub Desktop.
PHP: CSV export from MySql to output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$out = ''; | |
$fields = dibi::fetchAll("SHOW COLUMNS FROM web_application"); | |
foreach ($fields as $field) | |
{ | |
$out .= '"'.$field->Field.'";'; | |
} | |
$out = rtrim($out, ';'); | |
$out .= PHP_EOL; | |
foreach ($this->model->csvExport() as $index => $row) | |
{ | |
foreach ($row as $r) | |
{ | |
$out .='"'.$r.'";'; | |
} | |
$out = rtrim($out, ';'); | |
$out .= PHP_EOL; | |
} | |
$out = iconv('utf-8', 'windows-1250', $out); | |
$filename = 'application-export___' . date('YmdHis') . '.csv'; | |
header('Content-Encoding: windows-1250'); | |
header('Content-type: text/csv; charset=windows-1250'); | |
header('Content-Disposition: attachment; filename=' . $filename); | |
//echo "\xEF\xBB\xBF"; // UTF-8 BOM | |
echo $out; | |
exit(0); | |
$this->view->setTemplateFile('modules/application/csv.php'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment