数据库导出excel
<?php
$filename = "info.xls";
//先定义一个excel文件
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Disposition:attachment;filename='{$filename}'");
header("Content-Transfer-Encoding:binary");
//我们先在excel输出表头,当然这不是必须的
echo iconv("utf-8", "gb2312", "姓名") . "\t";
echo iconv("utf-8", "gb2312", "手机") . "\t";
echo iconv("utf-8", "gb2312", "日期") . "\t";
echo iconv("utf-8", "gb2312", "地区") . "\t";
echo iconv("utf-8", "gb2312", "详细区域") . "\t";
echo iconv("utf-8", "gb2312", "预购车型") . "\n";
//注意这个要换行
//这里我们定义一个数据库为datebse 数据库用户名:root 密码为:123456
$conn = mysql_connect("localhost", "gdcarvip88YH", "gdcarvipsH778");
mysql_select_db("gdcarvip888");
//这个是数据库名
//需要加这句,不知道为什么,不然导出的中文乱码,大家在使用的时候,如果utf8乱码,就改为GBK,反正也可以
mysql_query('set names utf8');
//查询的表条件
$sql = "select title,mycall,tqsj,dyx,address,ygcx from 表名";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo iconv("utf-8", "gb2312", $row['title']) . "\t";
echo iconv("utf-8", "gb2312", $row['mycall']) . "\t";
echo iconv("utf-8", "gb2312", $row['tqsj']) . "\t";
echo iconv("utf-8", "gb2312", $row['dyx']) . "\t";
echo iconv("utf-8", "gb2312", $row['address']) . "\t";
echo iconv("utf-8", "gb2312", $row['ygcx']) . "\n";
}
--------------------------------------------------------------------
承接网站开发、小程序开发、app开发、商城开发、公众号开发。
百度SEO排名、百度搜索霸屏、软文代写等业务。
联系QQ:2779459018 联系微信:qianxia39