Realize database of XML backup Mysql with PHP
Tuesday, March 03, 2009 by rain
File one, Listtable.php (the file is listed all form in the database,Back up for the choice)
Choose to want the form of backup please:
%26lt; ?
$con=mysql_connect('localhost' , 'root' , 'xswlily');
$lists=mysql_list_tables("embed" , $con);
/ / database join code
$i=0;While($i
";
/ / listed all form
$i++;}
? %26gt;
File two, Backup.php
%26lt; ? If ($table=="") Header("Location:lIsttable.php"); ? %26gt;
%26lt; ?
$con=mysql_connect('localhost' , 'root' , 'xswlily');
$query="select * From $table ";
/ / database inquiry
$result=mysql_db_query("embed" , $query, $con);
$filestr=%26quot;%26lt;%26quot; . "? Xml Version=\"1.0\" Encoding=\"GB2312\" ? ". "%26Gt;";
$filestr. =%26quot;%26lt;%26quot; . $table. "S%26gt; %26quot;;While ($row=mysql_fetch_array($result) )
/ / listed all records
{$filestr. =%26quot;%26lt;%26quot; . $table. "%26Gt;";
$fields=mysql_list_fields("embed" , $table, $con);
$j=0;
/ / $num_fields=mysql_field_name($fields, $j);
/ / Echo $num_fields;While ($j
$filestr. =%26quot;%26lt;%26quot; . $num_fields. "%26Gt;";
$filestr. =$row[$j];
$filestr. = "".$NUM_FIELDS.">";
$j++;}
$filestr. = "".$TABLE.">";
}
$filestr. = "".$TABLE."S>";Echo $filestr;
/ / it is file operation code below
$filename=$table. ". Xml";
$fp=fopen("$filename" , "W");Fwrite($fp, $filestr);Fclose($fp);
Echo " data expresses " . $table. "?oes bifurcation ? mound does Fu bask in ? ? ; ? %26gt;
The form of the make choice of in can realizing pair of databases through the operation of above file undertakes backup.
The operation method that above basically introduced to realize XML backup database through PHP,Actually not complex,Through XML,We can back up various databases,In also can passing relevant method to restore the XML documentation of backup the database of course,Did not describe in detail here.