mysql|xml| Backup | data | database
Here is the file code for backing up the MySQL database via apache+php under Linux:
File one, listtable.php (file lists all tables in the database for backup selection)
Please select the table you want to back up:
?
$con =mysql_connect (' localhost ', ' root ', ' xswlily ');
$lists =mysql_list_tables ("embed", $con);
Database Connection Code
$i = 0;
while ($i $tb_name=mysql_tablename ($lists, $i);
echo "". $TB _name. "
";
List all the tables
$i + +;}
?>
Document II, backup.php
<?if ($table = = "") Header ("Location:listtable.php");? >
?
$con =mysql_connect (' localhost ', ' root ', ' xswlily ');
$query = "SELECT * from $table";
Database query
$result =mysql_db_query ("Embed", $query, $con);
$filestr = "<"? XML version=\ "1.0\" encoding=\ "gb2312\"? "." > ";
$filestr. = "<". $table. " S> ";
while ($row =mysql_fetch_array ($result))
List all the records
{$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;
Here is the file manipulation code
$filename = $table. ". XML ";
$FP =fopen ("$filename", "w");
Fwrite ($fp, $FILESTR);
Fclose ($FP);
Echo "Datasheet". $table. " Backup has been successful! ";? >
By using the above files, you can perform a backup of the tables selected in the database.
The above introduces the implementation of XML backup database through PHP operation method, in fact, is not complex, through XML, we can back up a variety of databases, of course, can also be related to the method of the backup of the XML document back to the database, here is not described in detail.