mysql数据库转存到EXCEL

Header( "Content-type:   application/octet-stream "); 
Header( "Accept-Ranges: bytes ");
Header( "Content-type:application/vnd.ms-excel ");
Header( "Content-Disposition:attachment;filename=test.xls ");
$con = mysql_connect("localhost","root","123456");
mysql_select_db("db_test");
mysql_query('set names utf8');
$sql = "select id,FirstName,LastName,Age,Hometown,Job from user";
$result = mysql_query($sql,$con);
echo "id\tFirstName\tLastName\tAge\tHometown\tJob";
while ($rs=mysql_fetch_array($result)){
echo "\n";
echo $rs['id']."\t".$rs['FirstName']."\t".$rs['LastName']."\t".$rs['Age']."\t".$rs['Hometown']."\t".$rs['Job'];
}
posted @ 2014-03-12 08:46  寂夜冷风  阅读(426)  评论(0编辑  收藏  举报