2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2009-08-29 13:57:50 +00:00
|
|
|
$TABLE = $_GET["dump"];
|
2009-09-01 13:09:14 +00:00
|
|
|
|
2013-04-17 15:48:59 +00:00
|
|
|
if ($_POST && !$error) {
|
2010-04-21 12:01:32 +00:00
|
|
|
$cookie = "";
|
2011-01-19 13:32:35 +00:00
|
|
|
foreach (array("output", "format", "db_style", "routines", "events", "table_style", "auto_increment", "triggers", "data_style") as $key) {
|
2010-04-21 12:01:32 +00:00
|
|
|
$cookie .= "&$key=" . urlencode($_POST[$key]);
|
|
|
|
}
|
|
|
|
cookie("adminer_export", substr($cookie, 1));
|
2013-04-16 17:37:10 +00:00
|
|
|
$tables = array_flip((array) $_POST["tables"]) + array_flip((array) $_POST["data"]);
|
|
|
|
$ext = dump_headers(
|
|
|
|
(count($tables) == 1 ? key($tables) : DB),
|
|
|
|
(DB == "" || count($tables) > 1));
|
2013-07-24 23:26:41 +00:00
|
|
|
$is_sql = preg_match('~sql~', $_POST["format"]);
|
|
|
|
|
2010-10-22 19:27:53 +00:00
|
|
|
if ($is_sql) {
|
2014-02-21 17:15:59 +00:00
|
|
|
echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump\n\n";
|
|
|
|
if ($jush == "sql") {
|
2015-03-06 17:36:20 +00:00
|
|
|
echo "SET NAMES utf8;
|
2014-02-21 17:09:09 +00:00
|
|
|
SET time_zone = '+00:00';
|
2014-02-21 17:09:46 +00:00
|
|
|
" . ($_POST["data_style"] ? "SET foreign_key_checks = 0;
|
2009-08-28 11:49:57 +00:00
|
|
|
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
|
2012-08-12 05:37:30 +00:00
|
|
|
" : "") . "
|
2014-02-21 17:15:59 +00:00
|
|
|
";
|
2014-02-21 17:09:09 +00:00
|
|
|
$connection->query("SET time_zone = '+00:00';");
|
|
|
|
}
|
2008-08-16 12:28:31 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-06-01 12:53:19 +00:00
|
|
|
$style = $_POST["db_style"];
|
2010-04-21 12:01:32 +00:00
|
|
|
$databases = array(DB);
|
|
|
|
if (DB == "") {
|
|
|
|
$databases = $_POST["databases"];
|
|
|
|
if (is_string($databases)) {
|
|
|
|
$databases = explode("\n", rtrim(str_replace("\r", "", $databases), "\n"));
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2010-04-21 12:01:32 +00:00
|
|
|
foreach ((array) $databases as $db) {
|
2013-04-04 01:49:05 +00:00
|
|
|
$adminer->dumpDatabase($db);
|
2009-09-22 10:51:40 +00:00
|
|
|
if ($connection->select_db($db)) {
|
2013-07-24 23:26:41 +00:00
|
|
|
if ($is_sql && preg_match('~CREATE~', $style) && ($create = $connection->result("SHOW CREATE DATABASE " . idf_escape($db), 1))) {
|
2015-03-06 17:36:20 +00:00
|
|
|
set_utf8mb4($create);
|
2009-06-01 12:53:19 +00:00
|
|
|
if ($style == "DROP+CREATE") {
|
2009-10-02 12:31:28 +00:00
|
|
|
echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n";
|
2008-08-18 15:18:16 +00:00
|
|
|
}
|
2013-04-04 01:49:05 +00:00
|
|
|
echo "$create;\n";
|
2008-08-19 09:19:18 +00:00
|
|
|
}
|
2010-10-22 19:27:53 +00:00
|
|
|
if ($is_sql) {
|
2009-09-25 11:29:46 +00:00
|
|
|
if ($style) {
|
2010-04-21 22:37:16 +00:00
|
|
|
echo use_sql($db) . ";\n\n";
|
2009-10-13 12:47:53 +00:00
|
|
|
}
|
2008-09-01 16:49:38 +00:00
|
|
|
$out = "";
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-09-25 11:29:46 +00:00
|
|
|
if ($_POST["routines"]) {
|
2008-08-19 09:19:18 +00:00
|
|
|
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
2010-10-13 16:59:15 +00:00
|
|
|
foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) {
|
2015-03-06 17:36:20 +00:00
|
|
|
$create = remove_definer($connection->result("SHOW CREATE $routine " . idf_escape($row["Name"]), 2));
|
|
|
|
set_utf8mb4($create);
|
|
|
|
$out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . "$create;;\n\n";
|
2008-08-19 09:19:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-09-25 11:29:46 +00:00
|
|
|
if ($_POST["events"]) {
|
2010-10-13 16:59:15 +00:00
|
|
|
foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) {
|
2015-03-06 17:36:20 +00:00
|
|
|
$create = remove_definer($connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3));
|
|
|
|
set_utf8mb4($create);
|
|
|
|
$out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . "$create;;\n\n";
|
2008-09-01 16:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-08-28 11:49:57 +00:00
|
|
|
if ($out) {
|
2009-10-02 12:31:28 +00:00
|
|
|
echo "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n";
|
2009-08-28 11:49:57 +00:00
|
|
|
}
|
2008-08-19 09:19:18 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-06-01 12:53:19 +00:00
|
|
|
if ($_POST["table_style"] || $_POST["data_style"]) {
|
2008-08-19 09:19:18 +00:00
|
|
|
$views = array();
|
2013-04-27 03:04:57 +00:00
|
|
|
foreach (table_status('', true) as $name => $table_status) {
|
2013-04-27 01:54:19 +00:00
|
|
|
$table = (DB == "" || in_array($name, (array) $_POST["tables"]));
|
|
|
|
$data = (DB == "" || in_array($name, (array) $_POST["data"]));
|
2009-06-01 12:53:19 +00:00
|
|
|
if ($table || $data) {
|
2013-04-29 22:42:39 +00:00
|
|
|
if ($ext == "tar") {
|
2013-05-01 16:33:23 +00:00
|
|
|
$tmp_file = new TmpFile;
|
|
|
|
ob_start(array($tmp_file, 'write'), 1e5);
|
2013-04-29 22:42:39 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2013-04-29 22:42:39 +00:00
|
|
|
$adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0));
|
|
|
|
if (is_view($table_status)) {
|
2013-04-27 01:54:19 +00:00
|
|
|
$views[] = $name;
|
2013-04-29 22:42:39 +00:00
|
|
|
} elseif ($data) {
|
|
|
|
$fields = fields($name);
|
|
|
|
$adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name));
|
|
|
|
}
|
|
|
|
if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) {
|
|
|
|
echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2013-04-29 22:42:39 +00:00
|
|
|
if ($ext == "tar") {
|
2013-05-01 16:33:23 +00:00
|
|
|
ob_end_flush();
|
|
|
|
tar_file((DB != "" ? "" : "$db/") . "$name.csv", $tmp_file);
|
2013-04-29 22:42:39 +00:00
|
|
|
} elseif ($is_sql) {
|
|
|
|
echo "\n";
|
2008-08-19 09:19:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-06-01 12:53:19 +00:00
|
|
|
foreach ($views as $view) {
|
2013-04-29 22:42:39 +00:00
|
|
|
$adminer->dumpTable($view, $_POST["table_style"], 1);
|
2008-08-18 15:18:16 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-08-18 10:29:08 +00:00
|
|
|
if ($ext == "tar") {
|
2009-10-02 12:31:28 +00:00
|
|
|
echo pack("x512");
|
2009-08-18 10:29:08 +00:00
|
|
|
}
|
2008-08-16 12:28:31 +00:00
|
|
|
}
|
2008-08-08 15:00:42 +00:00
|
|
|
}
|
2008-06-20 14:13:37 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2010-10-22 19:27:53 +00:00
|
|
|
if ($is_sql) {
|
|
|
|
echo "-- " . $connection->result("SELECT NOW()") . "\n";
|
|
|
|
}
|
2008-06-20 14:13:37 +00:00
|
|
|
exit;
|
|
|
|
}
|
2007-08-04 19:40:11 +00:00
|
|
|
|
2013-07-05 08:31:53 +00:00
|
|
|
page_header(lang('Export'), $error, ($_GET["export"] != "" ? array("table" => $_GET["export"]) : array()), h(DB));
|
2008-06-20 14:13:37 +00:00
|
|
|
?>
|
|
|
|
|
|
|
|
<form action="" method="post">
|
2009-06-01 12:53:19 +00:00
|
|
|
<table cellspacing="0">
|
2009-05-31 22:31:09 +00:00
|
|
|
<?php
|
2009-08-25 15:23:19 +00:00
|
|
|
$db_style = array('', 'USE', 'DROP+CREATE', 'CREATE');
|
|
|
|
$table_style = array('', 'DROP+CREATE', 'CREATE');
|
2010-05-27 14:10:17 +00:00
|
|
|
$data_style = array('', 'TRUNCATE+INSERT', 'INSERT');
|
2013-07-05 16:04:06 +00:00
|
|
|
if ($jush == "sql") { //! use insertUpdate() in all drivers
|
2010-05-27 14:10:17 +00:00
|
|
|
$data_style[] = 'INSERT+UPDATE';
|
2009-06-01 12:53:19 +00:00
|
|
|
}
|
2010-04-21 12:01:32 +00:00
|
|
|
parse_str($_COOKIE["adminer_export"], $row);
|
|
|
|
if (!$row) {
|
|
|
|
$row = array("output" => "text", "format" => "sql", "db_style" => (DB != "" ? "" : "CREATE"), "table_style" => "DROP+CREATE", "data_style" => "INSERT");
|
|
|
|
}
|
2011-01-19 13:32:35 +00:00
|
|
|
if (!isset($row["events"])) { // backwards compatibility
|
|
|
|
$row["routines"] = $row["events"] = ($_GET["dump"] == "");
|
2011-04-20 15:15:16 +00:00
|
|
|
$row["triggers"] = $row["table_style"];
|
2011-01-19 13:32:35 +00:00
|
|
|
}
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2010-10-29 15:11:00 +00:00
|
|
|
echo "<tr><th>" . lang('Output') . "<td>" . html_select("output", $adminer->dumpOutput(), $row["output"], 0) . "\n"; // 0 - radio
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2010-10-29 15:11:00 +00:00
|
|
|
echo "<tr><th>" . lang('Format') . "<td>" . html_select("format", $adminer->dumpFormat(), $row["format"], 0) . "\n"; // 0 - radio
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2010-05-27 14:10:17 +00:00
|
|
|
echo ($jush == "sqlite" ? "" : "<tr><th>" . lang('Database') . "<td>" . html_select('db_style', $db_style, $row["db_style"])
|
2011-01-19 13:32:35 +00:00
|
|
|
. (support("routine") ? checkbox("routines", 1, $row["routines"], lang('Routines')) : "")
|
|
|
|
. (support("event") ? checkbox("events", 1, $row["events"], lang('Events')) : "")
|
2010-05-27 14:10:17 +00:00
|
|
|
);
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2010-05-03 16:09:13 +00:00
|
|
|
echo "<tr><th>" . lang('Tables') . "<td>" . html_select('table_style', $table_style, $row["table_style"])
|
2011-01-19 13:32:35 +00:00
|
|
|
. checkbox("auto_increment", 1, $row["auto_increment"], lang('Auto Increment'))
|
|
|
|
. (support("trigger") ? checkbox("triggers", 1, $row["triggers"], lang('Triggers')) : "")
|
2010-05-03 16:09:13 +00:00
|
|
|
;
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2010-04-21 12:01:32 +00:00
|
|
|
echo "<tr><th>" . lang('Data') . "<td>" . html_select('data_style', $data_style, $row["data_style"]);
|
2009-05-31 22:31:09 +00:00
|
|
|
?>
|
|
|
|
</table>
|
2010-03-02 16:33:28 +00:00
|
|
|
<p><input type="submit" value="<?php echo lang('Export'); ?>">
|
2013-04-17 15:48:59 +00:00
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
2008-06-20 14:13:37 +00:00
|
|
|
|
2009-06-21 23:49:04 +00:00
|
|
|
<table cellspacing="0">
|
2008-06-20 14:13:37 +00:00
|
|
|
<?php
|
2010-02-16 10:52:13 +00:00
|
|
|
$prefixes = array();
|
2010-01-09 23:33:41 +00:00
|
|
|
if (DB != "") {
|
|
|
|
$checked = ($TABLE != "" ? "" : " checked");
|
2009-06-03 09:17:20 +00:00
|
|
|
echo "<thead><tr>";
|
2018-01-12 15:51:45 +00:00
|
|
|
echo "<th style='text-align: left;'><label class='block'><input type='checkbox' id='check-tables'$checked>" . lang('Tables') . "</label>" . script("qs('#check-tables').onclick = partial(formCheck, /^tables\\[/);", "");
|
|
|
|
echo "<th style='text-align: right;'><label class='block'>" . lang('Data') . "<input type='checkbox' id='check-data'$checked></label>" . script("qs('#check-data').onclick = partial(formCheck, /^data\\[/);", "");
|
2009-07-11 20:30:40 +00:00
|
|
|
echo "</thead>\n";
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-05-31 22:31:09 +00:00
|
|
|
$views = "";
|
2013-05-18 00:40:08 +00:00
|
|
|
$tables_list = tables_list();
|
|
|
|
foreach ($tables_list as $name => $type) {
|
2013-07-24 23:26:41 +00:00
|
|
|
$prefix = preg_replace('~_.*~', '', $name);
|
2010-02-16 10:52:13 +00:00
|
|
|
$checked = ($TABLE == "" || $TABLE == (substr($TABLE, -1) == "%" ? "$prefix%" : $name)); //! % may be part of table name
|
2018-01-11 16:00:39 +00:00
|
|
|
$print = "<tr><td>" . checkbox("tables[]", $name, $checked, $name, "checkboxClick.call(this, event); formUncheck('check-tables');", "block");
|
2013-07-24 23:26:41 +00:00
|
|
|
if ($type !== null && !preg_match('~table~i', $type)) {
|
2009-07-11 20:30:40 +00:00
|
|
|
$views .= "$print\n";
|
2009-05-31 22:31:09 +00:00
|
|
|
} else {
|
2018-01-11 16:00:39 +00:00
|
|
|
echo "$print<td align='right'><label class='block'><span id='Rows-" . h($name) . "'></span>" . checkbox("data[]", $name, $checked, "", "checkboxClick.call(this, event); formUncheck('check-data');") . "</label>\n";
|
2008-07-31 14:28:26 +00:00
|
|
|
}
|
2010-02-16 10:52:13 +00:00
|
|
|
$prefixes[$prefix]++;
|
2008-06-20 14:13:37 +00:00
|
|
|
}
|
2009-06-21 23:49:04 +00:00
|
|
|
echo $views;
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2013-05-18 00:40:08 +00:00
|
|
|
if ($tables_list) {
|
2018-01-12 14:27:44 +00:00
|
|
|
echo script("ajaxSetHtml('" . js_escape(ME) . "script=db');");
|
2013-05-18 00:40:08 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-06-21 23:49:04 +00:00
|
|
|
} else {
|
2018-01-12 15:51:45 +00:00
|
|
|
echo "<thead><tr><th style='text-align: left;'>";
|
|
|
|
echo "<label class='block'><input type='checkbox' id='check-databases'" . ($TABLE == "" ? " checked" : "") . ">" . lang('Database') . "</label>";
|
|
|
|
echo script("qs('#check-databases').onclick = partial(formCheck, /^databases\\[/);", "");
|
|
|
|
echo "</thead>\n";
|
2012-02-24 06:54:48 +00:00
|
|
|
$databases = $adminer->databases();
|
2010-04-21 12:01:32 +00:00
|
|
|
if ($databases) {
|
|
|
|
foreach ($databases as $db) {
|
|
|
|
if (!information_schema($db)) {
|
2013-07-24 23:26:41 +00:00
|
|
|
$prefix = preg_replace('~_.*~', '', $db);
|
2013-05-20 17:06:23 +00:00
|
|
|
echo "<tr><td>" . checkbox("databases[]", $db, $TABLE == "" || $TABLE == "$prefix%", $db, "formUncheck('check-databases');", "block") . "\n";
|
2010-04-21 12:01:32 +00:00
|
|
|
$prefixes[$prefix]++;
|
|
|
|
}
|
2009-06-21 23:49:04 +00:00
|
|
|
}
|
2010-04-21 12:01:32 +00:00
|
|
|
} else {
|
2011-03-21 12:53:48 +00:00
|
|
|
echo "<tr><td><textarea name='databases' rows='10' cols='20'></textarea>";
|
2009-06-21 23:49:04 +00:00
|
|
|
}
|
2008-06-20 14:13:37 +00:00
|
|
|
}
|
|
|
|
?>
|
2009-06-21 23:49:04 +00:00
|
|
|
</table>
|
2008-06-20 14:13:37 +00:00
|
|
|
</form>
|
2010-02-16 10:52:13 +00:00
|
|
|
<?php
|
|
|
|
$first = true;
|
|
|
|
foreach ($prefixes as $key => $val) {
|
|
|
|
if ($key != "" && $val > 1) {
|
|
|
|
echo ($first ? "<p>" : " ") . "<a href='" . h(ME) . "dump=" . urlencode("$key%") . "'>" . h($key) . "</a>";
|
|
|
|
$first = false;
|
|
|
|
}
|
|
|
|
}
|