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) {
|
2007-07-10 13:30:42 +00:00
|
|
|
global $mysql;
|
2007-07-02 05:51:26 +00:00
|
|
|
static $routines;
|
|
|
|
if (!isset($routines)) {
|
|
|
|
$routines = array();
|
2007-07-10 13:30:42 +00:00
|
|
|
if ($mysql->server_info >= 5) {
|
2007-07-06 16:06:08 +00:00
|
|
|
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
2007-07-10 13:30:42 +00:00
|
|
|
$result = $mysql->query("SHOW $routine STATUS");
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
2007-07-06 16:06:08 +00:00
|
|
|
if (!strlen($_GET["db"]) || $row["Db"] === $_GET["db"]) {
|
2007-07-11 08:24:03 +00:00
|
|
|
$routines[$row["Db"]][] = $mysql->result($mysql->query("SHOW CREATE $routine " . idf_escape($row["Db"]) . "." . idf_escape($row["Name"])), 2) . ";;\n\n";
|
2007-07-06 16:06:08 +00:00
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$result->free();
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 13:30:42 +00:00
|
|
|
$result = $mysql->query("SHOW CREATE DATABASE " . idf_escape($db));
|
2007-07-06 13:03:13 +00:00
|
|
|
if ($result) {
|
2007-07-11 08:24:03 +00:00
|
|
|
echo $mysql->result($result, 1) . ";\n";
|
2007-07-10 13:30:42 +00:00
|
|
|
$result->free();
|
2007-07-06 13:03:13 +00:00
|
|
|
}
|
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";
|
2007-07-10 13:30:42 +00:00
|
|
|
$result = $mysql->query("SHOW TABLE STATUS");
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
$result1 = $mysql->query("SHOW CREATE TABLE " . idf_escape($row["Name"]));
|
2007-07-06 13:03:13 +00:00
|
|
|
if ($result1) {
|
2007-07-11 08:24:03 +00:00
|
|
|
echo $mysql->result($result1, 1) . ";\n";
|
2007-07-10 13:30:42 +00:00
|
|
|
$result1->free();
|
2007-07-09 06:12:22 +00:00
|
|
|
if (isset($row["Engine"])) {
|
2007-07-10 13:30:42 +00:00
|
|
|
$result1 = $mysql->query("SELECT * FROM " . idf_escape($row["Name"])); //! enum and set as numbers
|
2007-07-09 06:12:22 +00:00
|
|
|
if ($result1) {
|
2007-07-10 13:30:42 +00:00
|
|
|
while ($row1 = $result1->fetch_row()) {
|
2007-07-11 11:36:09 +00:00
|
|
|
echo "INSERT INTO " . idf_escape($row["Name"]) . " VALUES ('" . implode("', '", array_map(array($mysql, 'escape_string'), $row1)) . "');\n";
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$result1->free();
|
2007-07-06 13:03:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "\n";
|
2007-07-04 14:54:30 +00:00
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$result->free();
|
2007-07-02 05:51:26 +00:00
|
|
|
|
2007-07-10 13:30:42 +00:00
|
|
|
if ($mysql->server_info >= 5) {
|
|
|
|
$result = $mysql->query("SHOW TRIGGERS");
|
|
|
|
if ($result->num_rows || $routines[$db]) {
|
2007-07-06 16:06:08 +00:00
|
|
|
echo "DELIMITER ;;\n\n";
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
while ($row = $result->fetch_assoc()) {
|
2007-07-06 16:06:08 +00:00
|
|
|
echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n";
|
|
|
|
}
|
|
|
|
echo implode("", (array) $routines[$db]);
|
2007-07-10 13:30:42 +00:00
|
|
|
if ($result->num_rows || $routines[$db]) {
|
2007-07-06 16:06:08 +00:00
|
|
|
echo "DELIMITER ;\n\n";
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$result->free();
|
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 {
|
2007-07-10 13:30:42 +00:00
|
|
|
$result = $mysql->query("SHOW DATABASES");
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
if ($row["Database"] != "information_schema" || $mysql->server_info < 5) {
|
|
|
|
if ($mysql->select_db($row["Database"])) {
|
2007-07-02 05:51:26 +00:00
|
|
|
dump($row["Database"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$result->free();
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|