echo '<p><a href="' . htmlspecialchars($SELF) . 'schema=">' . lang('Database schema') . "</a></p>\n";
echo "<h3>" . lang('Tables and views') . "</h3>\n";
-$result = $dbh->query("SHOW TABLE STATUS");
-if (!$result->num_rows) {
+$table_status = table_status();
+if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<form action='' method='post'>\n";
echo "<table cellspacing='0' class='nowrap'>\n";
echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="form_check(this, /^(tables|views)\[/);" /></td><th>' . lang('Table') . '</th><td>' . lang('Engine') . '</td><td>' . lang('Collation') . '</td><td>' . lang('Data Length') . '</td><td>' . lang('Index Length') . '</td><td>' . lang('Data Free') . '</td><td>' . lang('Auto Increment') . '</td><td>' . lang('Rows') . '</td><td>' . lang('Comment') . "</td></tr></thead>\n";
- while ($row = $result->fetch_assoc()) {
+ foreach ($table_status as $row) {
$name = $row["Name"];
table_comment($row);
echo '<tr' . odd() . '><td><input type="checkbox" name="' . (isset($row["Rows"]) ? 'tables' : 'views') . '[]" value="' . htmlspecialchars($name) . '"' . (in_array($name, $tables_views, true) ? ' checked="checked"' : '') . ' onclick="form_uncheck(\'check-all\');" /></td>';
}
echo "</form>\n";
}
-$result->free();
if ($dbh->server_info >= 5) {
echo '<p><a href="' . htmlspecialchars($SELF) . 'createv=">' . lang('Create view') . "</a></p>\n";
if ($_POST["table_style"] || $_POST["data_style"]) {
$views = array();
- $result = $dbh->query("SHOW TABLE STATUS");
- while ($row = $result->fetch_assoc()) {
+ foreach (table_status() as $row) {
$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) {
}
}
}
- $result->free();
foreach ($views as $view) {
dump_table($view, $_POST["table_style"], true);
}
echo "<th align='right'><label>" . lang('Data') . "<input type='checkbox' id='check-data'$checked onclick='form_check(this, /^data\\[/);' /></label></th>";
echo "</tr></thead>\n";
$views = "";
- $result = $dbh->query("SHOW TABLE STATUS");
- while ($row = $result->fetch_assoc()) {
+ foreach (table_status() as $row) {
$checked = (strlen($_GET["dump"]) && $row["Name"] != $_GET["dump"] ? '' : " checked='checked'");
$print = '<tr><td><label><input type="checkbox" name="tables[]" value="' . htmlspecialchars($row["Name"]) . "\"$checked onclick=\"form_uncheck('check-tables');\" />" . htmlspecialchars($row["Name"]) . "</label></td>";
if (!$row["Engine"]) {
}
page_header(lang('Foreign key'), $error, array("table" => $_GET["foreign"]), $_GET["foreign"]);
-$tables = array();
-$result = $dbh->query("SHOW TABLE STATUS");
-while ($row = $result->fetch_assoc()) {
- if ($row["Engine"] == "InnoDB") {
- $tables[] = $row["Name"];
- }
-}
-$result->free();
-
if ($_POST) {
$row = $_POST;
ksort($row["source"]);
<form action="" method="post">
<p>
<?php echo lang('Target table'); ?>:
-<select name="table" onchange="this.form['change-js'].value = '1'; this.form.submit();"><?php echo optionlist($tables, $row["table"]); ?></select>
+<select name="table" onchange="this.form['change-js'].value = '1'; this.form.submit();"><?php echo optionlist(array_keys(table_status_referencable()), $row["table"]); ?></select>
<input type="hidden" name="change-js" value="" />
</p>
<noscript><p><input type="submit" name="change" value="<?php echo lang('Change'); ?>" /></p></noscript>
</form>
<?php
if ($missing != "db" && strlen($_GET["db"])) {
- $result = $dbh->query("SHOW TABLE STATUS");
- if (!$result->num_rows) {
+ $table_status = table_status();
+ if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
- while ($row = $result->fetch_assoc()) {
+ foreach ($table_status as $row) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . htmlspecialchars($row["Name"]) . "</a><br />\n";
}
echo "</p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
- $result->free();
}
}
?>
return $return;
}
-function table_status($table) {
+function table_status($name = "") {
global $dbh;
- $result = $dbh->query("SHOW TABLE STATUS LIKE " . $dbh->quote(addcslashes($table, "%_")));
- $return = $result->fetch_assoc(); // ()-> is not supported in PHP 4
+ $return = array();
+ $result = $dbh->query("SHOW TABLE STATUS" . (strlen($name) ? " LIKE " . $dbh->quote(addcslashes($name, "%_")) : ""));
+ while ($row = $result->fetch_assoc()) {
+ $return[$row["Name"]] = $row;
+ }
$result->free();
+ return (strlen($name) ? $return[$name] : $return);
+}
+
+function table_status_referencable() {
+ $return = array();
+ foreach (table_status() as $name => $row) {
+ if ($row["Engine"] == "InnoDB") {
+ $return[$name] = $row;
+ }
+ }
return $return;
}
$schema = array(); // table => array("fields" => array(name => field), "pos" => array(top, left), "references" => array(table => array(left => array(source, target))))
$referenced = array(); // target_table => array(table => array(left => target_column))
$lefts = array(); // float => bool
-$result = $dbh->query("SHOW TABLE STATUS");
-while ($row = $result->fetch_assoc()) {
+foreach (table_status() as $row) {
if (!isset($row["Engine"])) { // view
continue;
}
}
$top = max($top, $schema[$row["Name"]]["pos"][0] + 2.5 + $pos);
}
-$result->free();
?>
<div id="schema" style="height: <?php echo $top; ?>em;">