以下是在Linux下通過Apache+PHP對(duì)Mysql數(shù)據(jù)庫(kù)的備份的文件代碼: 文件一、Listtable.php (文件列出數(shù)據(jù)庫(kù)中的所有表格,供選擇備份)
請(qǐng)選擇要備份的表格: $con=mysql_connect('localhost','root','xswlily'); $query="select * from $table "; //數(shù)據(jù)庫(kù)查詢 $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)備份成功!";?>
通過以上文件的操作就可以實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)中選定的表格進(jìn)行備份. 以上主要介紹了通過PHP實(shí)現(xiàn)XML備份數(shù)據(jù)庫(kù)的操作方法,其實(shí)并不復(fù)雜,通過XML,我們可以備份各種各樣的數(shù)據(jù)庫(kù),當(dāng)然也可以通過相關(guān)的方法將備份的XML文檔恢復(fù)到數(shù)據(jù)庫(kù)中,這里就不詳細(xì)描述了。
|
溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!