This is a backup of all tables in a specified database into a SQL file, which can be downloaded.
-
- /****** Back up database structure ******/
-
- /*
- Function name: table2sql()
- Function function: Convert the table structure into SQL
- Function parameters: $table: To be performed Extracted table name
- Return value: Returns the extracted result, SQL collection
- Function author: heiyeluren
- */
-
- function table2sql($table)
- {
- global $db;
- $tabledump = "DROP TABLE IF EXISTS $table ;n";
- $createtable = $db--->query("SHOW CREATE TABLE $table");
- $create = $db->fetch_row($createtable);
- $tabledump .= $create[1 ].";nn";
- return $tabledump;
- }
-
-
- /****** Back up the database structure and all data ******/
- /*
- Function name: data2sql()
- Function: Convert the table structure and data into SQL
- Function Parameters: $table: The name of the table to be extracted
- Return value: Return the extracted results, SQL collection
- Function author: heiyeluren
- */
- function data2sql($table)
- {
- global $db;
- $tabledump = " DROP TABLE IF EXISTS $table;n";
- $createtable = $db->query("SHOW CREATE TABLE $table");
- $create = $db->fetch_row($createtable);
- $tabledump .= $create[1].";nn";
-
- $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( ";
- for($i = 0; $i < $numfields; $i++)
- {
- $tabledump .= $comma."'".mysql_escape_string($row[$i])."'";
- $ comma = ",";
- }
- $tabledump .= ");n";
- }
- $tabledump .= "n";
-
- return $tabledump;
- }
- ?>
-
-
|