Username: Password:

用 PHP 实现 XML 备份 Mysql 数据库-PHP教程,数据库相关
来源:作者: 发布时间:2007-12-26 02:10:58

以下是在linux下通过apache+php对mysql数据库的备份的文档代码:

文档一、listtable.php (文档列出数据库中的任何表格,供选择备份)


请选择要备份的表格:
$con=mysql_connect(localhost,root,xswlily);
$lists=mysql_list_tables("embed",$con);
//数据库连接代码
$i=0;
while($i$tb_name=mysql_tablename($lists,$i);
echo "".$tb_name."
";
//列出任何的表格
$i++;}

?>


文档二、backup.php


$con=mysql_connect(localhost,root,xswlily);
$query="select * from $table ";
//数据库查询
$result=mysql_db_query("embed",$query,$con);
$filestr="<"."?xml version="1.0" encoding="gb2312"?".">";
$filestr.="<".$table."s>";
while ($row=mysql_fetch_array($result))
//列出任何的记录
{$filestr.="<".$table.">";
$fields=mysql_list_fields("embed",$table,$con);
$j=0;
//$num_fields=mysql_field_name($fields,$j);
//echo $num_fields;
while ($j$num_fields=mysql_field_name($fields,$j);
$filestr.="<".$num_fields.">";
$filestr.=$row[$j];
$filestr.="";
$j++;}
$filestr.="";
}
$filestr.="";
echo $filestr;
//以下是文档操作代码
$filename=$table.".xml";
$fp=fopen("$filename","w");
fwrite($fp,$filestr);
fclose($fp);
echo "数据表".$table."已备份成功!";?>


通过以上文档的操作就能够实现对数据库中选定的表格进行备份.

以上主要介绍了通过php实现xml备份数据库的操作方法,其实并不复杂,通过xml,我们能够备份各种各样的数据库,当然也能够通过相关的方法将备份的xml文档恢复到数据库中,这里就不周详描述了。

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅