首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > PHP > 用PHP将mysql数据表转换为excel文件格式
【标  题】:用PHP将mysql数据表转换为excel文件格式
【关键字】:PHP,mysql,excel
【来  源】:http://blog.chinaunix.net/article.php?articleId=11519&blogId=2696

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

$DB_Server "localhost"
$DB_Username "mydowns"

$DB_Password ""

$DB_DBName "mydowns"

$DB_TBLName "user"

$Connect = @mysql_connect($DB_Server$DB_Username$DB_Password

or die(
"Couldn't connect."
); 
$Db = @mysql_select_db($DB_DBName$Connect

or die(
"Couldn't select database."
); 
$file_type "vnd.ms-excel"

$file_ending "xls"

header("Content-Type: application/$file_type"
); 
header("Content-Disposition: attachment; filename=mydowns.$file_ending"
); 
header("Pragma: no-cache"
); 
header("Expires: 0"
); 
$now_date date('Y-m-d H:i'
); 
$title "数据库名:$DB_DBName,数据表:$DB_TBLName,备份日期:$now_date"

$sql "Select * from $DB_TBLName"

$ALT_Db = @mysql_select_db($DB_DBName$Connect

or die(
"Couldn't select database"
); 
$result = @mysql_query($sql,$Connect

or die(
mysql_error
()); 
echo(
"$titlen"
); 
$sep "t"

for (
$i 0$i mysql_num_fields($result); $i
++) { 
echo 
mysql_field_name($result,$i) . "t"


print(
"n"
); 
$i 0

while(
$row mysql_fetch_row($result
)) 

$schema_insert ""

for(
$j=0$j<mysql_num_fields($result);$j
++) 

if(!isset(
$row[$j
])) 
$schema_insert .= "NULL".$sep

elseif (
$row[$j] != ""

$schema_insert .= "$row[$j]".$sep

else 
$schema_insert .= "".$sep


$schema_insert str_replace($sep."$"""$schema_insert
); 
$schema_insert .= "t"

print(
trim($schema_insert
)); 
print 
"n"

$i
++; 

return (
true
); 
?> 

PHP编程:探索字串的奥秘:【上一篇】
PHP遍历目录之一:【下一篇】
【相关文章】
  • PHP编程:探索字串的奥秘
  • 用PHP实现WEB动态网页静态化
  • PHP中接收复选框信息的方法
  • 关于PHP操作文件的一些FAQ总结
  • 如何用php通过odbc连到access数据库上?
  • PHP 5.0 Pear安装方法
  • 提升PHP执行速度全攻略(下)
  • 提升PHP执行速度全攻略(上)
  • 用PHP实现文件下载
  • 修改mysql密码的方法
  • 【随机文章】
  • Extending Python in IcePy
  • Curses例程[原创]
  • 教你制作“闻味的小狗”动画
  • IIS网站的护心甲——实战SSL
  • AC Report V1.71 For D567 (报表组件)
  • 什么是SDH?
  • C手册(英文的哦)
  • 保存在网页上看过的Flash文件
  • ASP.NET 2.0 - 如何于网页上新增包括图片在内的数据至数据库
  • 在SQL中操纵EXCEL
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.