diff --git a/dump.inc.php b/dump.inc.php index 047e01f4..98213333 100644 --- a/dump.inc.php +++ b/dump.inc.php @@ -16,18 +16,28 @@ function dump($db) { } } - echo "CREATE DATABASE IF NOT EXISTS " . idf_escape($db) . ";\n"; + $result = mysql_query("SHOW CREATE DATABASE " . idf_escape($db)); + if ($result) { + echo mysql_result($result, 0) . ";\n"; + mysql_free_result($result); + } echo "USE " . idf_escape($db) . ";\n"; echo "SET CHARACTER SET utf8;\n\n"; $result = mysql_query("SHOW TABLES"); while ($row = mysql_fetch_row($result)) { - echo mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($row[0])), 0, 1) . ";\n"; - $result1 = mysql_query("SELECT * FROM " . idf_escape($row[0])); //! except views //! enum and set as numbers - while ($row1 = mysql_fetch_row($result1)) { - echo "INSERT INTO " . idf_escape($row[0]) . " VALUES ('" . implode("', '", array_map('mysql_real_escape_string', $row1)) . "');\n"; + $result1 = mysql_query("SHOW CREATE TABLE " . idf_escape($row[0])); + if ($result1) { + echo mysql_result($result1, 0, 1) . ";\n"; + mysql_free_result($result1); + $result1 = mysql_query("SELECT * FROM " . idf_escape($row[0])); //! except views //! enum and set as numbers + if ($result1) { + while ($row1 = mysql_fetch_row($result1)) { + echo "INSERT INTO " . idf_escape($row[0]) . " VALUES ('" . implode("', '", array_map('mysql_real_escape_string', $row1)) . "');\n"; + } + mysql_free_result($result1); + } + echo "\n"; } - mysql_free_result($result1); - echo "\n"; } mysql_free_result($result); @@ -36,6 +46,7 @@ function dump($db) { echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];\n\n"; //! delimiter } mysql_free_result($result); + echo "\n\n"; echo implode("", (array) $routines[$db]); } diff --git a/functions.inc.php b/functions.inc.php index d35f4412..b9fce472 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -32,20 +32,23 @@ function optionlist($options, $selected = array(), $not_vals = false) { function fields($table) { $return = array(); $result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($table)); - while ($row = mysql_fetch_assoc($result)) { - preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match); - $return[$row["Field"]] = array( - "field" => $row["Field"], - "type" => $match[1], - "length" => $match[2], - "unsigned" => ltrim($match[3] . $match[4]), - "default" => $row["Default"], - "null" => ($row["Null"] != "NO"), - "extra" => $row["Extra"], - "collation" => $row["Collation"], - ); + if ($result) { + while ($row = mysql_fetch_assoc($result)) { + preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match); + $return[$row["Field"]] = array( + "field" => $row["Field"], + "type" => $match[1], + "length" => $match[2], + "unsigned" => ltrim($match[3] . $match[4]), + "default" => $row["Default"], + "null" => ($row["Null"] != "NO"), + "extra" => $row["Extra"], + "collation" => $row["Collation"], + "privileges" => explode(",", $row["Privileges"]), + ); + } + mysql_free_result($result); } - mysql_free_result($result); return $return; } @@ -63,12 +66,16 @@ function indexes($table) { function foreign_keys($table) { static $pattern = '~`((?:[^`]*|``)+)`~'; $return = array(); - $create_table = mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($table)), 0, 1); - preg_match_all('~FOREIGN KEY \\((.+)\\) REFERENCES (?:`(.+)`\\.)?`(.+)` \\((.+)\\)~', $create_table, $matches, PREG_SET_ORDER); - foreach ($matches as $match) { - preg_match_all($pattern, $match[1], $source); - preg_match_all($pattern, $match[4], $target); - $return[] = array(idf_unescape($match[2]), idf_unescape($match[3]), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1])); + $result = mysql_query("SHOW CREATE TABLE " . idf_escape($table)); + if ($result) { + $create_table = mysql_result($result, 0, 1); + mysql_free_result($result); + preg_match_all('~FOREIGN KEY \\((.+)\\) REFERENCES (?:`(.+)`\\.)?`(.+)` \\((.+)\\)~', $create_table, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + preg_match_all($pattern, $match[1], $source); + preg_match_all($pattern, $match[4], $target); + $return[] = array(idf_unescape($match[2]), idf_unescape($match[3]), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1])); + } } return $return; } diff --git a/select.inc.php b/select.inc.php index 0d1c6a26..9b3451d3 100644 --- a/select.inc.php +++ b/select.inc.php @@ -1,30 +1,39 @@ ' . lang('New item') . "
\n"; -echo "