久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

用PHP實現(xiàn)XML備份Mysql數(shù)據(jù)庫

瀏覽:118日期:2024-01-30 09:32:32

以下是在Linux下通過Apache+PHP對Mysql數(shù)據(jù)庫的備份的文件代碼:

文件一、Listtable.php (文件列出數(shù)據(jù)庫中的所有表格,供選擇備份)

請選擇要備份的表格: <? $con=mysql_connect('localhost','root','xswlily'); $lists=mysql_list_tables('embed',$con); //數(shù)據(jù)庫連接代碼 $i=0; while($i$tb_name=mysql_tablename($lists,$i); echo ''.$tb_name.' '; //列出所有的表格 $i++;}

?>

文件二、Backup.php <?if ($table=='') header('Location:listtable.php');?>

<? $con=mysql_connect('localhost','root','xswlily'); $query='select * from $table '; //數(shù)據(jù)庫查詢 $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 '數(shù)據(jù)表'.$table.'已經(jīng)備份成功!';?>

通過以上文件的操作就可以實現(xiàn)對數(shù)據(jù)庫中選定的表格進(jìn)行備份.

以上主要介紹了通過PHP實現(xiàn)XML備份數(shù)據(jù)庫的操作方法,其實并不復(fù)雜,通過XML,我們可以備份各種各樣的數(shù)據(jù)庫,當(dāng)然也可以通過相關(guān)的方法將備份的XML文檔恢復(fù)到數(shù)據(jù)庫中,這里就不詳細(xì)描述了。

標(biāo)簽: PHP
主站蜘蛛池模板: 汕头市| 萨嘎县| 青河县| 宁河县| 新宁县| 蓬溪县| 永仁县| 澄城县| 札达县| 磐安县| 连山| 柘荣县| 普兰店市| 错那县| 高尔夫| 临颍县| 离岛区| 奉新县| 克东县| 双峰县| 湟中县| 精河县| 丰镇市| 巴里| 濉溪县| 正安县| 金川县| 海口市| 读书| 炉霍县| 武冈市| 河津市| 永登县| 兴安县| 修水县| 二手房| 泰和县| 伊宁县| 静安区| 会泽县| 东平县|