Using PHP to implement XML backup Mysql database _php tutorial

Source: Internet
Author: User
Here is the file code for backup of MySQL database via Apache PHP under Linux:
File one, listtable.php (file lists all tables in the database for backup selection)
Please select a table 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

$con =mysql_connect (' localhost ', ' root ', ' xswlily ');
$query = "SELECT * from $table";
Database queries
$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 operation code
$filename = $table. ". XML ";
$FP =fopen ("$filename", "w");
Fwrite ($fp, $FILESTR);
Fclose ($FP);
Echo "Data Sheet". $table. " The backup has been successful! ";? >
Using the above file, you can make a backup of the selected tables in the database.
The above mainly introduces the implementation of XML backup database through PHP operation method, in fact, not complicated, through XML, we can back up a variety of databases, of course, you can also use the relevant method to restore the backup XML document to the database, here is not described in detail.

http://www.bkjia.com/PHPjc/631060.html www.bkjia.com true http://www.bkjia.com/PHPjc/631060.html techarticle here is the file code for the backup of MySQL database via Apache PHP under Linux: File one, listtable.php (file lists all the tables in the database for backup selection) Please select ...

  • 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.