2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2007-07-04 14:54:30 +00:00
|
|
|
header("Content-Type: text/plain; charset=utf-8");
|
2007-07-02 05:51:26 +00:00
|
|
|
|
|
|
|
function dump($db) {
|
|
|
|
static $routines;
|
2007-07-06 16:06:08 +00:00
|
|
|
static $version;
|
2007-07-02 05:51:26 +00:00
|
|
|
if (!isset($routines)) {
|
2007-07-06 16:06:08 +00:00
|
|
|
$version = mysql_get_server_info();
|
2007-07-02 05:51:26 +00:00
|
|
|
$routines = array();
|
2007-07-06 16:06:08 +00:00
|
|
|
if ($version >= 5) {
|
|
|
|
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
|
|
|
$result = mysql_query("SHOW $routine STATUS");
|
|
|
|
while ($row = mysql_fetch_assoc($result)) {
|
|
|
|
if (!strlen($_GET["db"]) || $row["Db"] === $_GET["db"]) {
|
|
|
|
$routines[$row["Db"]][] = mysql_result(mysql_query("SHOW CREATE $routine " . idf_escape($row["Db"]) . "." . idf_escape($row["Name"])), 0, 2) . ";;\n\n";
|
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-06 16:06:08 +00:00
|
|
|
mysql_free_result($result);
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-06 13:03:13 +00:00
|
|
|
$result = mysql_query("SHOW CREATE DATABASE " . idf_escape($db));
|
|
|
|
if ($result) {
|
2007-07-06 16:06:08 +00:00
|
|
|
echo mysql_result($result, 0, 1) . ";\n";
|
2007-07-06 13:03:13 +00:00
|
|
|
mysql_free_result($result);
|
|
|
|
}
|
2007-07-02 06:00:11 +00:00
|
|
|
echo "USE " . idf_escape($db) . ";\n";
|
2007-07-02 05:51:26 +00:00
|
|
|
echo "SET CHARACTER SET utf8;\n\n";
|
|
|
|
$result = mysql_query("SHOW TABLES");
|
|
|
|
while ($row = mysql_fetch_row($result)) {
|
2007-07-06 13:03:13 +00:00
|
|
|
$result1 = mysql_query("SHOW CREATE TABLE " . idf_escape($row[0]));
|
|
|
|
if ($result1) {
|
|
|
|
echo mysql_result($result1, 0, 1) . ";\n";
|
|
|
|
mysql_free_result($result1);
|
|
|
|
$result1 = mysql_query("SELECT * FROM " . idf_escape($row[0])); //! except views //! enum and set as numbers
|
|
|
|
if ($result1) {
|
|
|
|
while ($row1 = mysql_fetch_row($result1)) {
|
|
|
|
echo "INSERT INTO " . idf_escape($row[0]) . " VALUES ('" . implode("', '", array_map('mysql_real_escape_string', $row1)) . "');\n";
|
|
|
|
}
|
|
|
|
mysql_free_result($result1);
|
|
|
|
}
|
|
|
|
echo "\n";
|
2007-07-04 14:54:30 +00:00
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
|
2007-07-06 16:06:08 +00:00
|
|
|
if ($version >= 5) {
|
|
|
|
$result = mysql_query("SHOW TRIGGERS");
|
|
|
|
$triggers = mysql_num_rows($result);
|
|
|
|
if ($triggers || $routines[$db]) {
|
|
|
|
echo "DELIMITER ;;\n\n";
|
|
|
|
}
|
|
|
|
while ($row = mysql_fetch_assoc($result)) {
|
|
|
|
echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n";
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
echo implode("", (array) $routines[$db]);
|
|
|
|
if ($triggers || $routines[$db]) {
|
|
|
|
echo "DELIMITER ;\n\n";
|
|
|
|
}
|
2007-07-02 06:00:11 +00:00
|
|
|
}
|
|
|
|
|
2007-07-06 16:06:08 +00:00
|
|
|
echo "\n\n";
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($_GET["db"])) {
|
|
|
|
dump($_GET["db"]);
|
|
|
|
} else {
|
|
|
|
$result = mysql_query("SHOW DATABASES");
|
|
|
|
while ($row = mysql_fetch_assoc($result)) {
|
2007-07-06 09:55:51 +00:00
|
|
|
if ($row["Database"] != "information_schema" || mysql_get_server_info() < 5) {
|
2007-07-02 05:51:26 +00:00
|
|
|
if (mysql_select_db($row["Database"])) {
|
|
|
|
dump($row["Database"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
}
|