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 Articles by Author
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11