Implementing XML Backup MySQL database with PHP

Source: Internet
Author: User
The following is the file code for backing up MySQL databases under Linux via Apache PHP:
File one, listtable.php (file lists all tables in the database for backup selection)
<title>
Use XML to back up the MySQL database </title><meta http-equiv= "Content-type" content= text/html; charset=gb2312 ">
<body bgcolor= "#FFFFFF" text= "#000000" >
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<mysql_num_rows ($lists)) {
$tb_name=mysql_tablename ($lists,$i);
echo "<a href=backup.php?table=". $tb_name. " > ". $tb_name." </a>
";
List all the tables
$i;}
?>
</body>

Document II, backup.php
<?if ($table== "") Header ("Location:listtable.php");? ><title>
Use XML to back up the MySQL database </title><meta http-equiv= "Content-type" content= text/html; charset=gb2312 ">
<body bgcolor= "#FFFFFF" text= "#000000" >
?
$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<mysql_num_fields ($fields)) {
$num_fields=mysql_field_name ($FIELDS,$J);
$filestr.= "<". $num_fields. " > ";
$FILESTR.=$ROW[$J];
$filestr.= "</". $num_fields. " > ";
$j;}
$filestr.= "</". $table. " > ";
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.