mysql 备份功能与恢复功能思路
备份
<?php $conn=mysql_connect("localhost","root","root") or die ("数据库连接失败"); mysql_select_db("test",$conn) or die(mysql_error()); mysql_query("set names utf8"); $tabledump = ""; $query = mysql_query("show tables",$conn); while($row = mysql_fetch_array($query)){ $data[] = $row; } foreach ($data as $key => $value) { $tabledump .= "DROP TABLE IF EXISTS `$value[0]`;\n"; $query1 = mysql_query("SHOW CREATE TABLE `$value[0]`",$conn); while($row1 = mysql_fetch_array($query1)){ $data1[] = $row1; } foreach ($data1 as $key1 => $value1) { $tabledump .= $value1[1].";\n\n"; } } file_put_contents("dump.sql", $tabledump); ?>
恢复
<?php $conn=mysql_connect("localhost","root","root") or die ("数据库连接失败"); mysql_select_db("test",$conn) or die(mysql_error()); mysql_query("set names utf8"); $sql = file_get_contents("dump.sql"); mysql_query($sql,$conn); ?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。