php 读取数据保存到csv

#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();
HTTPROOT | 自学PHP | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 石头哥 |微信小程序 |木讯 |备案
Copyright © 1998 - 2016 HTTPROOT.COM. All Rights Reserved httproot.com 版权所有