文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用PHP将mysql数据表转换为excel文件格式

用PHP将mysql数据表转换为excel文件格式

时间:2005-02-03  来源:litie123


[color="#0000cc"]$DB_Server [color="#006600"]= [color="#cc0000"]"localhost"[color="#006600"];  
[color="#0000cc"]$DB_Username [color="#006600"]= [color="#cc0000"]"mydowns"[color="#006600"];  
[color="#0000cc"]$DB_Password [color="#006600"]= [color="#cc0000"]""[color="#006600"];  
[color="#0000cc"]$DB_DBName [color="#006600"]= [color="#cc0000"]"mydowns"[color="#006600"];  
[color="#0000cc"]$DB_TBLName [color="#006600"]= [color="#cc0000"]"user"[color="#006600"];  
[color="#0000cc"]$Connect [color="#006600"]= @[color="#0000cc"]mysql_connect[color="#006600"]([color="#0000cc"]$DB_Server[color="#006600"], [color="#0000cc"]$DB_Username[color="#006600"], [color="#0000cc"]$DB_Password[color="#006600"])  
or die([color="#cc0000"]"Couldn't connect."[color="#006600"]);  
[color="#0000cc"]$Db [color="#006600"]= @[color="#0000cc"]mysql_select_db[color="#006600"]([color="#0000cc"]$DB_DBName[color="#006600"], [color="#0000cc"]$Connect[color="#006600"])  
or die([color="#cc0000"]"Couldn't select database."[color="#006600"]);  
[color="#0000cc"]$file_type [color="#006600"]= [color="#cc0000"]"vnd.ms-excel"[color="#006600"];  
[color="#0000cc"]$file_ending [color="#006600"]= [color="#cc0000"]"xls"[color="#006600"];  
[color="#0000cc"]header[color="#006600"]([color="#cc0000"]"Content-Type: application/$file_type"[color="#006600"]);  
[color="#0000cc"]header[color="#006600"]([color="#cc0000"]"Content-Disposition: attachment; filename=mydowns.$file_ending"[color="#006600"]);  
[color="#0000cc"]header[color="#006600"]([color="#cc0000"]"Pragma: no-cache"[color="#006600"]);  
[color="#0000cc"]header[color="#006600"]([color="#cc0000"]"Expires: 0"[color="#006600"]);  
[color="#0000cc"]$now_date [color="#006600"]= [color="#0000cc"]date[color="#006600"]([color="#cc0000"]'Y-m-d H:i'[color="#006600"]);  
[color="#0000cc"]$title [color="#006600"]= [color="#cc0000"]"数据库名:$DB_DBName,数据表:$DB_TBLName,备份日期:$now_date"[color="#006600"];  
[color="#0000cc"]$sql [color="#006600"]= [color="#cc0000"]"Select * from $DB_TBLName"[color="#006600"];  
[color="#0000cc"]$ALT_Db [color="#006600"]= @[color="#0000cc"]mysql_select_db[color="#006600"]([color="#0000cc"]$DB_DBName[color="#006600"], [color="#0000cc"]$Connect[color="#006600"])  
or die([color="#cc0000"]"Couldn't select database"[color="#006600"]);  
[color="#0000cc"]$result [color="#006600"]= @[color="#0000cc"]mysql_query[color="#006600"]([color="#0000cc"]$sql[color="#006600"],[color="#0000cc"]$Connect[color="#006600"])  
or die([color="#0000cc"]mysql_error[color="#006600"]());  
echo([color="#cc0000"]"$title[color="#006600"]n[color="#cc0000"]"[color="#006600"]);  
[color="#0000cc"]$sep [color="#006600"]= [color="#cc0000"]"t"[color="#006600"];  
for ([color="#0000cc"]$i [color="#006600"]= [color="#0000cc"]0[color="#006600"]; [color="#0000cc"]$i [color="#006600"][color="#006600"]++) {  
echo [color="#0000cc"]mysql_field_name[color="#006600"]([color="#0000cc"]$result[color="#006600"],[color="#0000cc"]$i[color="#006600"]) . [color="#cc0000"]"t"[color="#006600"];  
}  
print([color="#cc0000"]"n"[color="#006600"]);  
[color="#0000cc"]$i [color="#006600"]= [color="#0000cc"]0[color="#006600"];  
while([color="#0000cc"]$row [color="#006600"]= [color="#0000cc"]mysql_fetch_row[color="#006600"]([color="#0000cc"]$result[color="#006600"]))  
{  
[color="#0000cc"]$schema_insert [color="#006600"]= [color="#cc0000"]""[color="#006600"];  
for([color="#0000cc"]$j[color="#006600"]=[color="#0000cc"]0[color="#006600"]; [color="#0000cc"]$j[color="#006600"][color="#006600"]++)  
{  
if(!isset([color="#0000cc"]$row[color="#006600"][[color="#0000cc"]$j[color="#006600"]]))  
[color="#0000cc"]$schema_insert [color="#006600"].= [color="#cc0000"]"NULL"[color="#006600"].[color="#0000cc"]$sep[color="#006600"];  
elseif ([color="#0000cc"]$row[color="#006600"][[color="#0000cc"]$j[color="#006600"]] != [color="#cc0000"]""[color="#006600"])  
[color="#0000cc"]$schema_insert [color="#006600"].= [color="#cc0000"]"$row[color="#006600"][[color="#cc0000"]$j[color="#006600"]][color="#cc0000"]"[color="#006600"].[color="#0000cc"]$sep[color="#006600"];  
else  
[color="#0000cc"]$schema_insert [color="#006600"].= [color="#cc0000"]""[color="#006600"].[color="#0000cc"]$sep[color="#006600"];  
}  
[color="#0000cc"]$schema_insert [color="#006600"]= [color="#0000cc"]str_replace[color="#006600"]([color="#0000cc"]$sep[color="#006600"].[color="#cc0000"]"[color="#006600"]$[color="#cc0000"]"[color="#006600"], [color="#cc0000"]""[color="#006600"], [color="#0000cc"]$schema_insert[color="#006600"]);  
[color="#0000cc"]$schema_insert [color="#006600"].= [color="#cc0000"]"t"[color="#006600"];  
print([color="#0000cc"]trim[color="#006600"]([color="#0000cc"]$schema_insert[color="#006600"]));  
print [color="#cc0000"]"n"[color="#006600"];  
[color="#0000cc"]$i[color="#006600"]++;  
}  
return ([color="#0000cc"]true[color="#006600"]);  
[color="#0000cc"]?>  


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载