This is an SQL file that backs up all tables in a specified database and can be downloaded. This source code comes from the dedecms program. It has many functions and is very practical, but the quality of the Code remains to be improved.
- <!? Php
- /****** Back up the database structure ******/
- /*
- Function Name: table2sql ()
- Function: converts the table structure to SQL
- Function parameter: $ table: name of the table to be extracted
- Return Value: return the extracted results, SQL set
- Function Author: heiyeluren
- */
- Function table2sql ($ table)
- {
- Global $ db;
- $ Tabledump = "drop table if exists $ table ;";
- $ Createtable = $ db ---> query ("show create table $ table ");
- $ Create = $ db-> fetch_row ($ createtable );
- $ Tabledump. = $ create [1]. ";";
- Return $ tabledump;
- }
- /****** Back up the database structure and all data ******/
- /*
- Function Name: data2sql ()
- Function: converts the table structure and data into SQL statements.
- Function parameter: $ table: name of the table to be extracted
- Return Value: return the extracted results, SQL set
- Function Author: heiyeluren
- */
- Function data2sql ($ table)
- {
- Global $ db;
- $ Tabledump = "drop table if exists $ table ;";
- $ Createtable = $ db-> query ("show create table $ table ");
- $ Create = $ db-> fetch_row ($ createtable );
- $ Tabledump. = $ create [1]. ";";
- $ Rows = $ db-> query ("SELECT * FROM $ table ");
- $ Numfields = $ db-> num_fields ($ rows );
- $ Numrows = $ db-> num_rows ($ rows );
- While ($ row = $ db-> fetch_row ($ rows ))
- {
- $ Comma = "";
- $ Tabledump. = "insert into $ table VALUES (";