#sql语句
select
'姓名' u_name,
'密码' u_password,
'微信OPENID' u_wxopenid
union all
select
t.u_name,
t.u_password,
t.u_wxopenid
from mhsw_user t
实例:
$Result = $Model->query($sql_select);
foreach ($Result as $i => $row) {
foreach ($row as $j => $v) {
$row[$j] = iconv('utf-8', 'gb2312', $v);
}
$Result[$i] = $row;
}
header('Content-Type: text/csv;');
header('Content-Disposition: attachment; filename=export.csv');
$output = fopen('php://output', 'w');
foreach($Result as $row)
{
fputcsv($output, $row);
}
exit();