Beispiel #1
0
 /** Export table structure
  * @param string
  * @param string
  * @param int 0 table, 1 view, 2 temporary view table
  * @return null prints data
  */
 function dumpTable($table, $style, $is_view = 0)
 {
     if ($_POST["format"] != "sql") {
         echo "";
         // UTF-8 byte order mark
         if ($style) {
             dump_csv(array_keys(fields($table)));
         }
     } else {
         if ($is_view == 2) {
             $fields = array();
             foreach (fields($table) as $name => $field) {
                 $fields[] = idf_escape($name) . " {$field['full_type']}";
             }
             $create = "CREATE TABLE " . table($table) . " (" . implode(", ", $fields) . ")";
         } else {
             $create = create_sql($table, $_POST["auto_increment"]);
         }
         set_utf8mb4($create);
         if ($style && $create) {
             if ($style == "DROP+CREATE" || $is_view == 1) {
                 echo "DROP " . ($is_view == 2 ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
             }
             if ($is_view == 1) {
                 $create = remove_definer($create);
             }
             echo "{$create};\n\n";
         }
     }
 }
Beispiel #2
0
 }
 if ($is_sql) {
     if ($style) {
         echo use_sql($db) . ";\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" : "") . remove_definer($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" : "") . remove_definer($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('', true) as $name => $table_status) {
         $table = DB == "" || in_array($name, (array) $_POST["tables"]);
         $data = DB == "" || in_array($name, (array) $_POST["data"]);
         if ($table || $data) {
             if ($ext == "tar") {
                 $tmp_file = new TmpFile();
                 ob_start(array($tmp_file, 'write'), 100000.0);
Beispiel #3
0
     if ($style) {
         echo use_sql($db) . ";\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) {
                 $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";
             }
         }
     }
     if ($_POST["events"]) {
         foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) {
             $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";
         }
     }
     if ($out) {
         echo "DELIMITER ;;\n\n{$out}" . "DELIMITER ;\n\n";
     }
 }
 if ($_POST["table_style"] || $_POST["data_style"]) {
     $views = array();
     foreach (table_status('', true) as $name => $table_status) {
         $table = DB == "" || in_array($name, (array) $_POST["tables"]);
         $data = DB == "" || in_array($name, (array) $_POST["data"]);
         if ($table || $data) {
             if ($ext == "tar") {