server_info >= 5) { $result = $dbh->query("SHOW TRIGGERS LIKE '" . $dbh->escape_string(addcslashes($table, "%_")) . "'"); if ($result->num_rows) { echo "\nDELIMITER ;;\n"; while ($row = $result->fetch_assoc()) { echo "\nCREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n"; } echo "\nDELIMITER ;\n"; } $result->free(); } } if ($_POST) { $ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"]), (!strlen($_GET["db"]) || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1)); if ($_POST["format"] != "csv") { echo "SET NAMES utf8;\n"; echo "SET foreign_key_checks = 0;\n"; echo "SET time_zone = '" . $dbh->escape_string($dbh->result($dbh->query("SELECT @@time_zone"))) . "';\n"; echo "\n"; } $style = $_POST["db_style"]; foreach ((strlen($_GET["db"]) ? array($_GET["db"]) : (array) $_POST["databases"]) as $db) { if ($dbh->select_db($db)) { if ($_POST["format"] != "csv" && ereg('CREATE', $style) && ($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape($db)))) { if ($style == "DROP+CREATE") { echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n"; } $create = $dbh->result($result, 1); echo ($style == "CREATE+ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n"; $result->free(); } if ($style && $_POST["format"] != "csv") { echo "USE " . idf_escape($db) . ";\n\n"; $out = ""; if ($dbh->server_info >= 5) { foreach (array("FUNCTION", "PROCEDURE") as $routine) { $result = $dbh->query("SHOW $routine STATUS WHERE Db = '" . $dbh->escape_string($db) . "'"); while ($row = $result->fetch_assoc()) { $out .= $dbh->result($dbh->query("SHOW CREATE $routine " . idf_escape($row["Name"])), 2) . ";;\n\n"; } $result->free(); } } if ($dbh->server_info >= 5.1) { $result = $dbh->query("SHOW EVENTS"); while ($row = $result->fetch_assoc()) { $out .= $dbh->result($dbh->query("SHOW CREATE EVENT " . idf_escape($row["Name"])), 3) . ";;\n\n"; } $result->free(); } echo ($out ? "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n" : ""); } if ($_POST["table_style"] || $_POST["data_style"]) { $views = array(); $result = $dbh->query("SHOW TABLE STATUS"); while ($row = $result->fetch_assoc()) { $table = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["tables"])); $data = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["data"])); if ($table || $data) { if (isset($row["Engine"])) { if ($ext == "tar") { ob_start(); } dump_table($row["Name"], ($table ? $_POST["table_style"] : "")); if ($data) { dump_data($row["Name"], $_POST["data_style"]); } if ($table) { dump_triggers($row["Name"], $_POST["table_style"]); } if ($ext == "tar") { echo tar_file((strlen($_GET["db"]) ? "" : "$db/") . "$row[Name].csv", ob_get_clean()); } elseif ($_POST["format"] != "csv") { echo "\n"; } } elseif ($_POST["format"] != "csv") { $views[] = $row["Name"]; } } } $result->free(); foreach ($views as $view) { dump_table($view, $_POST["table_style"], true); } } if ($style == "CREATE+ALTER" && $_POST["format"] != "csv") { $query = "SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()"; ?> DELIMITER ;; CREATE PROCEDURE adminer_drop () BEGIN DECLARE _table_name, _engine, _table_collation varchar(64); DECLARE _table_comment varchar(64); DECLARE done bool DEFAULT 0; DECLARE tables CURSOR FOR ; 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_namequery($query); while ($row = $result->fetch_assoc()) { $comment = $dbh->escape_string($row["ENGINE"] == "InnoDB" ? preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["TABLE_COMMENT"]) : $row["TABLE_COMMENT"]); echo " WHEN '" . $dbh->escape_string($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") . ";"; } $result->free(); ?> ELSE SET @alter_table = CONCAT('DROP TABLE `', REPLACE(_table_name, '`', '``'), '`'); PREPARE alter_command FROM @alter_table; EXECUTE alter_command; -- returns "can't return a result set in the given context" with MySQL extension DROP PREPARE alter_command; END CASE; END IF; UNTIL done END REPEAT; CLOSE tables; END;; DELIMITER ; CALL adminer_drop; DROP PROCEDURE adminer_drop; $_GET["export"]) : array()), $_GET["db"]); ?>