教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php mysql备份的代码(xml应用)

php mysql备份的代码(xml应用)

发布时间:2015-09-26   编辑:jiaochengji.com
为大家提供一段代码:php结合xml文件实现mysql数据表的备份,代码简洁易懂,适合初学的朋友参考。

1、Listtable.php,用途:列出待备份的表
 

复制代码 代码示例:
<?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++;}
?>

2、Backup.php 开始数据表的备份
 

复制代码 代码示例:

<?php
//备份开始
if ($table=="") header("Location:listtable.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 mysql备份的另类思路,借助xml文件实现了mysql数据表的备份。
脚本学堂,祝大家学习进步,实现自己的中国梦,呵呵。

您可能感兴趣的文章:
php mysql备份的代码(xml应用)
php Mysql数据库备份类及调用方法
mysql命令之备份数据库
mysql备份与同步脚本
貌似很强的mysql备份策略
mysql备份并压缩存档的shell脚本
Linux下备份与还原整个MySQL整个数据库的脚本
vps自动备份shell脚本代码
导出mysql所有用户权限的shell脚本
windows中MYSQL数据库自动备份及自动清理之掉备份的批处理文件

关键词: mysql备份   
[关闭]
~ ~