git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@353 7c3ca157-0c34-0410-bff1-cbf682f78f5c
104 lines
3.1 KiB
PHP
104 lines
3.1 KiB
PHP
<?php
|
|
header("Content-Type: text/plain; charset=utf-8");
|
|
$filename = (strlen($_GET["db"]) ? preg_replace('~[^a-z0-9_]~i', '-', (strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"])) : "dump");
|
|
header("Content-Disposition: inline; filename=$filename.sql");
|
|
|
|
function dump_table($table, $data = true) {
|
|
global $mysql;
|
|
$result = $mysql->query("SHOW CREATE TABLE " . idf_escape($table));
|
|
if ($result) {
|
|
echo $mysql->result($result, 1) . ";\n\n";
|
|
$result->free();
|
|
if ($data) {
|
|
$result = $mysql->query("SELECT * FROM " . idf_escape($table)); //! enum and set as numbers, binary as _binary, microtime
|
|
if ($result) {
|
|
while ($row = $result->fetch_row()) {
|
|
foreach ($row as $key => $val) {
|
|
$row[$key] = (isset($val) ? "'" . $mysql->escape_string($val) . "'" : "NULL");
|
|
}
|
|
echo "INSERT INTO " . idf_escape($table) . " VALUES (" . implode(", ", $row) . ");\n";
|
|
}
|
|
$result->free();
|
|
}
|
|
echo "\n";
|
|
}
|
|
}
|
|
if ($mysql->server_info >= 5) {
|
|
$result = $mysql->query("SHOW TRIGGERS LIKE '" . $mysql->escape_string(addcslashes($table, "%_")) . "'");
|
|
if ($result->num_rows) {
|
|
echo "DELIMITER ;;\n\n";
|
|
while ($row = $result->fetch_assoc()) {
|
|
echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n";
|
|
}
|
|
echo "DELIMITER ;\n\n";
|
|
}
|
|
$result->free();
|
|
}
|
|
}
|
|
|
|
function dump($db) {
|
|
global $mysql;
|
|
static $routines;
|
|
if (!isset($routines)) {
|
|
$routines = array();
|
|
if ($mysql->server_info >= 5) {
|
|
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
|
$result = $mysql->query("SHOW $routine STATUS");
|
|
while ($row = $result->fetch_assoc()) {
|
|
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"])), 2) . ";;\n\n";
|
|
}
|
|
}
|
|
$result->free();
|
|
}
|
|
}
|
|
}
|
|
|
|
$views = array();
|
|
$result = $mysql->query("SHOW TABLE STATUS");
|
|
while ($row = $result->fetch_assoc()) {
|
|
if (isset($row["Engine"])) {
|
|
dump_table($row["Name"]);
|
|
} else {
|
|
$views[] = $row["Name"];
|
|
}
|
|
}
|
|
$result->free();
|
|
foreach ($views as $view) {
|
|
dump_table($view, false);
|
|
}
|
|
|
|
if ($routines[$db]) {
|
|
echo "DELIMITER ;;\n\n" . implode("", $routines[$db]) . "DELIMITER ;\n\n";
|
|
}
|
|
|
|
echo "\n\n";
|
|
}
|
|
|
|
echo "SET NAMES utf8;\n";
|
|
echo "SET FOREIGN_KEY_CHECKS = 0;\n";
|
|
echo "SET TIME_ZONE = '" . $mysql->escape_string($mysql->result($mysql->query("SELECT @@TIME_ZONE"))) . "';\n";
|
|
echo "\n";
|
|
|
|
if (!strlen($_GET["db"])) {
|
|
$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"])) {
|
|
$result1 = $mysql->query("SHOW CREATE DATABASE " . idf_escape($row["Database"]));
|
|
if ($result1) {
|
|
echo $mysql->result($result1, 1) . ";\n";
|
|
$result1->free();
|
|
}
|
|
echo "USE " . idf_escape($row["Database"]) . ";\n";
|
|
dump($row["Database"]);
|
|
}
|
|
}
|
|
}
|
|
$result->free();
|
|
} elseif (strlen($_GET["dump"])) {
|
|
dump_table($_GET["dump"]);
|
|
} else {
|
|
dump($_GET["db"]);
|
|
}
|