Home > Backend Development > PHP Tutorial > PHP backup database generates SQL file and downloads function code_PHP tutorial

PHP backup database generates SQL file and downloads function code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:20:59
Original
1006 people have browsed it

Copy code The code is as follows:

/****** Back up database structure ******/
/*
Function name: table2sql()
Function function: Convert the table structure into SQL
Function parameter: $table: the name of the table to be extracted
Return value: Return the extracted result, SQL Set
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 function : Convert the table structure and data into SQL
function parameters: $table: table name 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;
}
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template