用PHP實(shí)現(xiàn)XML備份Mysql數(shù)據(jù)庫
以下是在Linux下通過Apache+PHP對(duì)Mysql數(shù)據(jù)庫的備份的文件代碼:
文件一、Listtable.php (文件列出數(shù)據(jù)庫中的所有表格,供選擇備份)
請(qǐng)選擇要備份的表格:
<?
$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)備份成功!";?>
通過以上文件的操作就可以實(shí)現(xiàn)對(duì)數(shù)據(jù)庫中選定的表格進(jìn)行備份.
以上主要介紹了通過PHP實(shí)現(xiàn)XML備份數(shù)據(jù)庫的操作方法,其實(shí)并不復(fù)雜,通過XML,我們可以備份各種各樣的數(shù)據(jù)庫,當(dāng)然也可以通過相關(guān)的方法將備份的XML文檔恢復(fù)到數(shù)據(jù)庫中,這里就不詳細(xì)描述了。
- php生成mysql的數(shù)據(jù)字典
- PHP實(shí)現(xiàn)獲取并生成數(shù)據(jù)庫字典的方法
- ThinkPHP框架實(shí)現(xiàn)的MySQL數(shù)據(jù)庫備份功能示例
- PHP備份/還原MySQL數(shù)據(jù)庫的代碼
- php實(shí)現(xiàn)mysql數(shù)據(jù)庫備份類
- 使用PHP備份MYSQL數(shù)據(jù)的多種方法
- php MYSQL 數(shù)據(jù)備份類
- php實(shí)現(xiàn)MySQL數(shù)據(jù)庫備份與還原類實(shí)例
- 使用php自動(dòng)備份數(shù)據(jù)庫表的實(shí)現(xiàn)方法
- PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能示例
相關(guān)文章
PHP的FTP學(xué)習(xí)(一)[轉(zhuǎn)自奧索]
PHP的FTP學(xué)習(xí)(一)[轉(zhuǎn)自奧索]...2006-10-10
不用數(shù)據(jù)庫的多用戶文件自由上傳投票系統(tǒng)(1)
不用數(shù)據(jù)庫的多用戶文件自由上傳投票系統(tǒng)(1)...2006-10-10
php array_pop()數(shù)組函數(shù)將數(shù)組最后一個(gè)單元彈出(出棧)
函數(shù)array_pop():將數(shù)組最后一個(gè)單元彈出(出棧)2011-07-07
弄了個(gè)檢測傳輸?shù)膮?shù)是否為數(shù)字的Function
弄了個(gè)檢測傳輸?shù)膮?shù)是否為數(shù)字的Function...2006-12-12

