mirror of
https://github.com/vrana/adminer.git
synced 2026-07-30 16:00:57 +02:00
Database abstraction
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@97 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
62
dump.inc.php
62
dump.inc.php
@@ -2,65 +2,63 @@
|
||||
header("Content-Type: text/plain; charset=utf-8");
|
||||
|
||||
function dump($db) {
|
||||
global $mysql;
|
||||
static $routines;
|
||||
static $version;
|
||||
if (!isset($routines)) {
|
||||
$version = mysql_get_server_info();
|
||||
$routines = array();
|
||||
if ($version >= 5) {
|
||||
if ($mysql->server_info >= 5) {
|
||||
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
||||
$result = mysql_query("SHOW $routine STATUS");
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$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"])), 0, 2) . ";;\n\n";
|
||||
$routines[$row["Db"]][] = $mysql->result($mysql->query("SHOW CREATE $routine " . idf_escape($row["Db"]) . "." . idf_escape($row["Name"])), 0, 2) . ";;\n\n";
|
||||
}
|
||||
}
|
||||
mysql_free_result($result);
|
||||
$result->free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = mysql_query("SHOW CREATE DATABASE " . idf_escape($db));
|
||||
$result = $mysql->query("SHOW CREATE DATABASE " . idf_escape($db));
|
||||
if ($result) {
|
||||
echo mysql_result($result, 0, 1) . ";\n";
|
||||
mysql_free_result($result);
|
||||
echo $mysql->result($result, 0, 1) . ";\n";
|
||||
$result->free();
|
||||
}
|
||||
echo "USE " . idf_escape($db) . ";\n";
|
||||
echo "SET CHARACTER SET utf8;\n\n";
|
||||
$result = mysql_query("SHOW TABLE STATUS");
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$result1 = mysql_query("SHOW CREATE TABLE " . idf_escape($row["Name"]));
|
||||
$result = $mysql->query("SHOW TABLE STATUS");
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$result1 = $mysql->query("SHOW CREATE TABLE " . idf_escape($row["Name"]));
|
||||
if ($result1) {
|
||||
echo mysql_result($result1, 0, 1) . ";\n";
|
||||
mysql_free_result($result1);
|
||||
echo $mysql->result($result1, 0, 1) . ";\n";
|
||||
$result1->free();
|
||||
if (isset($row["Engine"])) {
|
||||
$result1 = mysql_query("SELECT * FROM " . idf_escape($row["Name"])); //! enum and set as numbers
|
||||
$result1 = $mysql->query("SELECT * FROM " . idf_escape($row["Name"])); //! enum and set as numbers
|
||||
if ($result1) {
|
||||
while ($row1 = mysql_fetch_row($result1)) {
|
||||
echo "INSERT INTO " . idf_escape($row["Name"]) . " VALUES ('" . implode("', '", array_map('mysql_real_escape_string', $row1)) . "');\n";
|
||||
while ($row1 = $result1->fetch_row()) {
|
||||
echo "INSERT INTO " . idf_escape($row["Name"]) . " VALUES ('" . implode("', '", array_map(array($mysql, 'real_escape_string'), $row1)) . "');\n";
|
||||
}
|
||||
mysql_free_result($result1);
|
||||
$result1->free();
|
||||
}
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
mysql_free_result($result);
|
||||
$result->free();
|
||||
|
||||
if ($version >= 5) {
|
||||
$result = mysql_query("SHOW TRIGGERS");
|
||||
$triggers = mysql_num_rows($result);
|
||||
if ($triggers || $routines[$db]) {
|
||||
if ($mysql->server_info >= 5) {
|
||||
$result = $mysql->query("SHOW TRIGGERS");
|
||||
if ($result->num_rows || $routines[$db]) {
|
||||
echo "DELIMITER ;;\n\n";
|
||||
}
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
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";
|
||||
}
|
||||
mysql_free_result($result);
|
||||
echo implode("", (array) $routines[$db]);
|
||||
if ($triggers || $routines[$db]) {
|
||||
if ($result->num_rows || $routines[$db]) {
|
||||
echo "DELIMITER ;\n\n";
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
|
||||
echo "\n\n";
|
||||
@@ -69,13 +67,13 @@ function dump($db) {
|
||||
if (strlen($_GET["db"])) {
|
||||
dump($_GET["db"]);
|
||||
} else {
|
||||
$result = mysql_query("SHOW DATABASES");
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
if ($row["Database"] != "information_schema" || mysql_get_server_info() < 5) {
|
||||
if (mysql_select_db($row["Database"])) {
|
||||
$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"])) {
|
||||
dump($row["Database"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
mysql_free_result($result);
|
||||
$result->free();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user