1)); $is_sql = ($_POST["format"] == "sql"); if ($is_sql) { echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump " . ($jush != "sql" ? "" : "SET NAMES utf8; SET foreign_key_checks = 0; SET time_zone = " . q($connection->result("SELECT @@time_zone")) . "; SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; "); } $style = $_POST["db_style"]; $databases = array(DB); if (DB == "") { $databases = $_POST["databases"]; if (is_string($databases)) { $databases = explode("\n", rtrim(str_replace("\r", "", $databases), "\n")); } } foreach ((array) $databases as $db) { if ($connection->select_db($db)) { if ($is_sql && ereg('CREATE', $style) && ($create = $connection->result("SHOW CREATE DATABASE " . idf_escape($db), 1))) { if ($style == "DROP+CREATE") { echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n"; } echo ($style == "CREATE+ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n"; } if ($is_sql) { if ($style) { echo use_sql($db) . ";\n\n"; } if (in_array("CREATE+ALTER", array($style, $_POST["table_style"]))) { echo "SET @adminer_alter = '';\n\n"; } $out = ""; if ($_POST["routines"]) { foreach (array("FUNCTION", "PROCEDURE") as $routine) { foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) { $out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . $connection->result("SHOW CREATE $routine " . idf_escape($row["Name"]), 2) . ";;\n\n"; } } } if ($_POST["events"]) { foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) { $out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . $connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3) . ";;\n\n"; } } if ($out) { echo "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n"; } } if ($_POST["table_style"] || $_POST["data_style"]) { $views = array(); foreach (table_status() as $table_status) { $table = (DB == "" || in_array($table_status["Name"], (array) $_POST["tables"])); $data = (DB == "" || in_array($table_status["Name"], (array) $_POST["data"])); if ($table || $data) { if (!is_view($table_status)) { if ($ext == "tar") { ob_start(); } $adminer->dumpTable($table_status["Name"], ($table ? $_POST["table_style"] : "")); if ($data) { $adminer->dumpData($table_status["Name"], $_POST["data_style"], "SELECT * FROM " . table($table_status["Name"])); } if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($table_status["Name"], $_POST["table_style"]))) { echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n"; } if ($ext == "tar") { echo tar_file((DB != "" ? "" : "$db/") . "$table_status[Name].csv", ob_get_clean()); } elseif ($is_sql) { echo "\n"; } } elseif ($is_sql) { $views[] = $table_status["Name"]; } } } foreach ($views as $view) { $adminer->dumpTable($view, $_POST["table_style"], true); } if ($ext == "tar") { echo pack("x512"); } } if ($style == "CREATE+ALTER" && $is_sql) { // drop old tables $query = "SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()"; echo "DELIMITER ;; CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN DECLARE _table_name, _engine, _table_collation varchar(64); DECLARE _table_comment varchar(64); DECLARE done bool DEFAULT 0; DECLARE tables CURSOR FOR $query; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN tables; REPEAT FETCH tables INTO _table_name, _engine, _table_collation, _table_comment; IF NOT done THEN CASE _table_name"; foreach (get_rows($query) as $row) { $comment = q($row["ENGINE"] == "InnoDB" ? preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["TABLE_COMMENT"]) : $row["TABLE_COMMENT"]); echo " WHEN " . q($row["TABLE_NAME"]) . " THEN " . (isset($row["ENGINE"]) ? "IF _engine != '$row[ENGINE]' OR _table_collation != '$row[TABLE_COLLATION]' OR _table_comment != $comment THEN ALTER TABLE " . idf_escape($row["TABLE_NAME"]) . " ENGINE=$row[ENGINE] COLLATE=$row[TABLE_COLLATION] COMMENT=$comment; END IF" : "BEGIN END") . ";"; } echo " ELSE SET alter_command = CONCAT(alter_command, 'DROP TABLE `', REPLACE(_table_name, '`', '``'), '`;\\n'); END CASE; END IF; UNTIL done END REPEAT; CLOSE tables; END;; DELIMITER ; CALL adminer_alter(@adminer_alter); DROP PROCEDURE adminer_alter; "; } if (in_array("CREATE+ALTER", array($style, $_POST["table_style"])) && $is_sql) { echo "SELECT @adminer_alter;\n"; } } } if ($is_sql) { echo "-- " . $connection->result("SELECT NOW()") . "\n"; } exit; } page_header(lang('Export'), "", ($_GET["export"] != "" ? array("table" => $_GET["export"]) : array()), DB); ?>
$val) { if ($key != "" && $val > 1) { echo ($first ? "" : " ") . "" . h($key) . ""; $first = false; } }