PHP XML備份Mysql數(shù)據(jù)庫
更新時間:2009年05月27日 17:00:13 作者:
以下是在Linux下通過Apache+PHP對Mysql數(shù)據(jù)庫的備份的文件代碼
用PHP實現(xiàn)XML備份Mysql數(shù)據(jù)庫 收藏
以下是在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ù)庫中選定的表格進行備份.
以上主要介紹了通過PHP實現(xiàn)XML備份數(shù)據(jù)庫的操作方法,其實并不復雜,通過XML,我們可以備份各種各樣的數(shù)據(jù)庫,當然也可以通過相關的方法將備份的XML文檔恢復到數(shù)據(jù)庫中,這里就不詳細描述了。
以下是在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ù)庫中選定的表格進行備份.
以上主要介紹了通過PHP實現(xiàn)XML備份數(shù)據(jù)庫的操作方法,其實并不復雜,通過XML,我們可以備份各種各樣的數(shù)據(jù)庫,當然也可以通過相關的方法將備份的XML文檔恢復到數(shù)據(jù)庫中,這里就不詳細描述了。
您可能感興趣的文章:
- PHP實現(xiàn)動態(tài)添加XML中數(shù)據(jù)的方法
- PHP解析xml格式數(shù)據(jù)工具類示例
- PHP操作XML作為數(shù)據(jù)庫的類
- PHP中使用xmlreader讀取xml數(shù)據(jù)示例
- PHP生成和獲取XML格式數(shù)據(jù)的方法
- php操作XML、讀取數(shù)據(jù)和寫入數(shù)據(jù)的實現(xiàn)代碼
- php中實現(xiàn)xml與mysql數(shù)據(jù)相互轉(zhuǎn)換的方法
- php處理復雜xml數(shù)據(jù)示例
- php操作xml并將其插入數(shù)據(jù)庫的實現(xiàn)方法
- PHP XML數(shù)據(jù)解析代碼
- PHP實現(xiàn)動態(tài)刪除XML數(shù)據(jù)的方法示例
相關文章
php多種形式發(fā)送郵件(mail qmail郵件系統(tǒng) phpmailer類)
這篇文章主要介紹了php多種形式發(fā)送郵件的方法,包括使用mail()函數(shù)、使用管道的形式、使用phpmailer類等方法,大家參考使用吧2014-01-01

