Implement XML backup mysql database with PHP

xiaoxiao2021-03-06  41

The following is a file code for backed up by Apache PHP under Linux:

File 1. ListTable.php (file lists all the forms in the database for backup)

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 forms

$ I ;}

?>

File 2, backup.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 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;

// The following is the file operation code

$ filename = $ table. ". xml";

$ fp = fopen ("$ filename", "w");

FWRITE ($ FP, $ FileStr);

Fclose ($ fp);

Echo "Data Sheet". $ TABLE. "It has been backup!";?>

A table selected in the database can be backed up by operating the above document.

转载请注明原文地址:https://www.9cbs.com/read-70558.html

New Post(0)