Database abstraction

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@97 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-10 13:30:42 +00:00
parent 01f52ebbf7
commit ae372aabba
18 changed files with 276 additions and 204 deletions

View file

@ -1,42 +1,116 @@
<?php <?php
if (extension_loaded("mysqli")) { if (extension_loaded("mysqli")) {
class Min_MySQLi extends MySQLi { class Min_MySQLi extends MySQLi {
function mysqli_result($result, $row, $field) { function Min_MySQLi() {
mysqli_data_seek($result, $row); $this->init();
$row = mysql_fetch_assoc($result); }
function connect($server, $username, $password) {
return $this->real_connect(
(strlen($server) ? $server : ini_get("mysqli.default_host")),
(strlen("$server$username") ? $username : ini_get("mysqli.default_user")),
(strlen("$server$username$password") ? $password : ini_get("mysqli.default_pw"))
);
}
function result($result, $offset, $field = 0) {
$result->data_seek($offset);
$row = $result->fetch_array();
return $row[$field]; return $row[$field];
} }
} }
$mysql = mysqli_init();
$mysql = new Min_MySQLi;
} elseif (extension_loaded("mysql")) { } elseif (extension_loaded("mysql")) {
class Min_MySQL { class Min_MySQL {
var $_link; var $_link, $_result, $server_info, $affected_rows, $error;
function real_connect($server, $username, $password) { return $this->_link = mysql_connect($server, $username, $password, false, 131072); }
function query($query) { return new Min_MySQLResult(mysql_query($query, $this->_link)); }
function result($result, $row, $field = 0) { return mysql_result($result->_result, $row, $field); }
function error() { return mysql_error($this->_link); }
function affected_rows() { return mysql_affected_rows($this->_link); }
function select_db($database) { return mysql_select_db($database, $this->_link); }
function real_escape_string($string) { return mysql_real_escape_string($string, $this->_link); }
function get_server_info() { return mysql_get_server_info($this->_link); }
function fetch_field($result, $offset = null) { function connect($server, $username, $password) {
$row = mysql_fetch_field($result, $offset); $this->_link = @mysql_pconnect(
(strlen($server) ? $server : ini_get("mysql.default_host")),
(strlen("$server$username") ? $username : ini_get("mysql.default_user")),
(strlen("$server$username$password") ? $password : ini_get("mysql.default_password")),
131072 // CLIENT_MULTI_RESULTS for CALL
);
if ($this->_link) {
$this->server_info = mysql_get_server_info($this->_link);
}
return (bool) $this->_link;
}
function query($query) {
$result = mysql_query($query, $this->_link);
if (!$result) {
$this->error = mysql_error($this->_link);
return false;
} elseif ($result === true) {
$this->affected_rows = mysql_affected_rows($this->_link);
return true;
}
return new Min_MySQLResult($result);
}
function multi_query($query) {
return $this->_result = $this->query($query);
}
function store_result() {
return $this->_result;
}
function next_result() {
return false;
}
function result($result, $offset, $field = 0) {
return mysql_result($result->_result, $offset, $field);
}
function select_db($database) {
return mysql_select_db($database, $this->_link);
}
function real_escape_string($string) {
return mysql_real_escape_string($string, $this->_link);
}
}
class Min_MySQLResult {
var $_result, $_offset, $num_rows;
function Min_MySQLResult($result) {
$this->_result = $result;
$this->_offset = 0;
$this->num_rows = mysql_num_rows($result);
}
function fetch_assoc() {
return mysql_fetch_assoc($this->_result);
}
function fetch_row() {
return mysql_fetch_row($this->_result);
}
function fetch_field() {
$row = mysql_fetch_field($this->_result, $this->_offset++);
$row->orgtable = $row->table; $row->orgtable = $row->table;
$row->orgname = $row->name; $row->orgname = $row->name;
$row->charsetnr = ($row->blob ? 63 : 0); $row->charsetnr = ($row->blob ? 63 : 0);
return $row; return $row;
} }
function free() {
return mysql_free_result($this->_result);
}
} }
class Min_MySQLResult {
var $_result;
function Min_MySQLResult($result) { $this->_result = $result; }
function fetch_assoc() { return mysql_fetch_assoc($this->_result); }
function fetch_row() { return mysql_fetch_row($this->_result); }
function free_result() { return mysql_free_result($this->_result); }
function num_rows() { return mysql_num_rows($this->_result); }
}
$mysql = new Min_MySQL;
} else {
$mysql = new Min_MySQL;
} else {
page_header(lang('No MySQL extension'));
echo "<p class='error'>" . lang('None of supported PHP extensions (%s) are available.', 'mysqli, mysql') . "</p>\n";
page_footer("auth");
exit;
} }

View file

@ -14,14 +14,7 @@ if (isset($_POST["server"])) {
$_SESSION["tokens"][$_GET["server"]] = array(); $_SESSION["tokens"][$_GET["server"]] = array();
} }
$username = $_SESSION["usernames"][$_GET["server"]]; if (isset($_GET["logout"]) || !$mysql->connect($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]])) {
$password = $_SESSION["passwords"][$_GET["server"]];
if (isset($_GET["logout"]) || !@mysql_connect(
(strlen($_GET["server"]) ? $_GET["server"] : ini_get("mysql.default_host")),
(strlen("$_GET[server]$username") ? $username : ini_get("mysql.default_user")),
(strlen("$_GET[server]$username$password") ? $password : ini_get("mysql.default_password")),
false, 131072 // CLIENT_MULTI_RESULTS for CALL
)) {
page_header(lang('Login')); page_header(lang('Login'));
if (isset($_GET["logout"])) { if (isset($_GET["logout"])) {
echo "<p class='message'>" . lang('Logout successful.') . "</p>\n"; echo "<p class='message'>" . lang('Logout successful.') . "</p>\n";
@ -32,7 +25,7 @@ if (isset($_GET["logout"]) || !@mysql_connect(
<form action="" method="post"> <form action="" method="post">
<table border="0" cellspacing="0" cellpadding="2"> <table border="0" cellspacing="0" cellpadding="2">
<tr><th><?php echo lang('Server'); ?>:</th><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" maxlength="60" /></td></tr> <tr><th><?php echo lang('Server'); ?>:</th><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" maxlength="60" /></td></tr>
<tr><th><?php echo lang('Username'); ?>:</th><td><input name="username" value="<?php echo htmlspecialchars($username); ?>" maxlength="16" /></td></tr> <tr><th><?php echo lang('Username'); ?>:</th><td><input name="username" value="<?php echo htmlspecialchars($_SESSION["usernames"][$_GET["server"]]); ?>" maxlength="16" /></td></tr>
<tr><th><?php echo lang('Password'); ?>:</th><td><input type="password" name="password" /></td></tr> <tr><th><?php echo lang('Password'); ?>:</th><td><input type="password" name="password" /></td></tr>
<tr><th><?php <tr><th><?php
foreach ($_POST as $key => $val) { // expired session foreach ($_POST as $key => $val) { // expired session
@ -60,4 +53,4 @@ if (isset($_GET["logout"]) || !@mysql_connect(
page_footer("auth"); page_footer("auth");
exit; exit;
} }
mysql_query("SET SQL_QUOTE_SHOW_CREATE=1"); $mysql->query("SET SQL_QUOTE_SHOW_CREATE=1");

View file

@ -1,10 +1,13 @@
<?php <?php
page_header(lang('Call') . ": " . htmlspecialchars($_GET["call"]));
function normalize_enum($match) { function normalize_enum($match) {
return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0]{0} . $match[0]{0}, $match[0]{0}, substr($match[0], 1, -1))), '\\')) . "'"; return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0]{0} . $match[0]{0}, $match[0]{0}, substr($match[0], 1, -1))), '\\')) . "'";
} }
$length = '\'(?:[^\'\\\\]*|\\\\.)+\'|"(?:[^"\\\\]*|\\\\.)+"'; $length = '\'(?:[^\'\\\\]*|\\\\.)+\'|"(?:[^"\\\\]*|\\\\.)+"';
$pattern = "\\s*(IN|OUT|INOUT)?\\s*(?:`((?:[^`]*|``)+)`\\s*|\\b(\\S+)\\s+)([a-z]+)(?:\\s*\\(((?:[^'\")]*|$length)+)\\))?\\s*(?:zerofill\\s+)?(unsigned)?"; $pattern = "\\s*(IN|OUT|INOUT)?\\s*(?:`((?:[^`]*|``)+)`\\s*|\\b(\\S+)\\s+)([a-z]+)(?:\\s*\\(((?:[^'\")]*|$length)+)\\))?\\s*(?:zerofill\\s+)?(unsigned)?";
$create = mysql_result(mysql_query("SHOW CREATE " . (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE") . " " . idf_escape($_GET["call"])), 0, 2); $create = $mysql->result($mysql->query("SHOW CREATE " . (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE") . " " . idf_escape($_GET["call"])), 0, 2);
preg_match("~\\($pattern(?:\\s*,$pattern)*~is", $create, $match); preg_match("~\\($pattern(?:\\s*,$pattern)*~is", $create, $match);
$in = array(); $in = array();
$out = array(); $out = array();
@ -26,43 +29,32 @@ foreach ($matches as $i => $match) {
} }
$params[$i] = $field; $params[$i] = $field;
} }
if ($_POST) { if ($_POST) {
$call = array(); $call = array();
foreach ($params as $key => $field) { foreach ($params as $key => $field) {
if (in_array($key, $in)) { if (in_array($key, $in)) {
$val = process_input($key, $field); $val = process_input($key, $field);
if (isset($out[$key])) { if (isset($out[$key])) {
mysql_query("SET @" . idf_escape($field["field"]) . " = " . $val); $mysql->query("SET @" . idf_escape($field["field"]) . " = " . $val);
} }
} }
$call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val); $call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val);
} }
$result = mysql_query((isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($_GET["call"]) . "(" . implode(", ", $call) . ")"); $result = $mysql->multi_query((isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($_GET["call"]) . "(" . implode(", ", $call) . ")");
if (!$result) { if (!$result) {
$error = mysql_error(); echo "<p class='error'>" . lang('Error during calling') . ": " . htmlspecialchars($mysql->error) . "</p>\n";
} elseif ($result === true) {
$message = lang('Routine has been called, %d row(s) affected.', mysql_affected_rows());
if (!$out) {
redirect(substr($SELF, 0, -1), $message);
}
}
}
page_header(lang('Call') . ": " . htmlspecialchars($_GET["call"]));
if ($_POST) {
if (!$result) {
echo "<p class='error'>" . lang('Error during calling') . ": " . htmlspecialchars($error) . "</p>\n";
} else { } else {
if ($result === true) { do {
echo "<p class='message'>$message</p>\n"; $result = $mysql->store_result();
} else { if (is_object($result)) {
select($result); select($result);
echo "<br />\n"; } else {
} echo "<p class='message'>" . lang('Routine has been called, %d row(s) affected.', $mysql->affected_rows) . "</p>\n";
}
} while ($mysql->next_result());
if ($out) { if ($out) {
select(mysql_query("SELECT " . implode(", ", $out))); select($mysql->query("SELECT " . implode(", ", $out)));
echo "<br />\n";
} }
} }
} }

View file

@ -1,5 +1,5 @@
<?php <?php
if (!(strlen($_GET["db"]) ? mysql_select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]))) { if (!(strlen($_GET["db"]) ? $mysql->select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]))) {
page_header(lang('Select database')); page_header(lang('Select database'));
if (strlen($_GET["db"])) { if (strlen($_GET["db"])) {
echo "<p class='error'>" . lang('Invalid database.') . "</p>\n"; echo "<p class='error'>" . lang('Invalid database.') . "</p>\n";
@ -9,4 +9,4 @@ if (!(strlen($_GET["db"]) ? mysql_select_db($_GET["db"]) : isset($_GET["sql"]) |
page_footer("db"); page_footer("db");
exit; exit;
} }
mysql_query("SET CHARACTER SET utf8"); $mysql->query("SET CHARACTER SET utf8");

View file

@ -29,10 +29,10 @@ if ($_POST && !$error && !$_POST["add"]) {
. idf_escape($field["field"]) . " $field[type]" . idf_escape($field["field"]) . " $field[type]"
. ($field["length"] ? "($field[length])" : "") . ($field["length"] ? "($field[length])" : "")
. (preg_match('~int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "") . (preg_match('~int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
. (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " COLLATE '" . mysql_real_escape_string($field["collation"]) . "'" : "") . (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " COLLATE '" . $mysql->real_escape_string($field["collation"]) . "'" : "")
. ($field["null"] ? "" : " NOT NULL") . ($field["null"] ? "" : " NOT NULL")
. ($key == $_POST["auto_increment"] ? " AUTO_INCREMENT$auto_increment_index" : "") . ($key == $_POST["auto_increment"] ? " AUTO_INCREMENT$auto_increment_index" : "")
. " COMMENT '" . mysql_real_escape_string($field["comment"]) . "'" . " COMMENT '" . $mysql->real_escape_string($field["comment"]) . "'"
. (strlen($_GET["create"]) && !strlen($field["orig"]) ? $after : "") . (strlen($_GET["create"]) && !strlen($field["orig"]) ? $after : "")
; ;
$after = "AFTER " . idf_escape($field["field"]); $after = "AFTER " . idf_escape($field["field"]);
@ -40,9 +40,9 @@ if ($_POST && !$error && !$_POST["add"]) {
$fields[] = "DROP " . idf_escape($field["orig"]); $fields[] = "DROP " . idf_escape($field["orig"]);
} }
} }
$status = ($_POST["Engine"] ? " ENGINE='" . mysql_real_escape_string($_POST["Engine"]) . "'" : "") $status = ($_POST["Engine"] ? " ENGINE='" . $mysql->real_escape_string($_POST["Engine"]) . "'" : "")
. ($_POST["Collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["Collation"]) . "'" : "") . ($_POST["Collation"] ? " COLLATE '" . $mysql->real_escape_string($_POST["Collation"]) . "'" : "")
. " COMMENT='" . mysql_real_escape_string($_POST["Comment"]) . "'" . " COMMENT='" . $mysql->real_escape_string($_POST["Comment"]) . "'"
; ;
if (strlen($_GET["create"])) { if (strlen($_GET["create"])) {
$query = "ALTER TABLE " . idf_escape($_GET["create"]) . " " . implode(", ", $fields) . ", RENAME TO " . idf_escape($_POST["name"]) . ", $status"; $query = "ALTER TABLE " . idf_escape($_GET["create"]) . " " . implode(", ", $fields) . ", RENAME TO " . idf_escape($_POST["name"]) . ", $status";
@ -52,10 +52,10 @@ if ($_POST && !$error && !$_POST["add"]) {
$message = lang('Table has been created.'); $message = lang('Table has been created.');
} }
} }
if (mysql_query($query)) { if ($mysql->query($query)) {
redirect(($_POST["drop"] ? substr($SELF, 0, -1) : $SELF . "table=" . urlencode($_POST["name"])), $message); redirect(($_POST["drop"] ? substr($SELF, 0, -1) : $SELF . "table=" . urlencode($_POST["name"])), $message);
} }
$error = mysql_error(); $error = $mysql->error;
} }
page_header(strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table')); page_header(strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table'));
@ -72,7 +72,8 @@ if ($_POST) {
$row["fields"][$row["auto_increment"]]["auto_increment"] = true; $row["fields"][$row["auto_increment"]]["auto_increment"] = true;
} }
} elseif (strlen($_GET["create"])) { } elseif (strlen($_GET["create"])) {
$row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'")); $result = $mysql->query("SHOW TABLE STATUS LIKE '" . $mysql->real_escape_string($_GET["create"]) . "'");
$row = $result->fetch_assoc();
$row["name"] = $_GET["create"]; $row["name"] = $_GET["create"];
$row["fields"] = array_values(fields($_GET["create"])); $row["fields"] = array_values(fields($_GET["create"]));
} else { } else {

View file

@ -1,30 +1,30 @@
<?php <?php
if ($_POST && !$error) { if ($_POST && !$error) {
if ($_POST["drop"]) { if ($_POST["drop"]) {
if (mysql_query("DROP DATABASE " . idf_escape($_GET["db"]))) { if ($mysql->query("DROP DATABASE " . idf_escape($_GET["db"]))) {
redirect(substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF), 0, -1), lang('Database has been dropped.')); redirect(substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF), 0, -1), lang('Database has been dropped.'));
} }
} elseif ($_GET["db"] !== $_POST["name"]) { } elseif ($_GET["db"] !== $_POST["name"]) {
if (mysql_query("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'" : ""))) { if ($mysql->query("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . $mysql->real_escape_string($_POST["collation"]) . "'" : ""))) {
if (!strlen($_GET["db"])) { if (!strlen($_GET["db"])) {
redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been created.')); redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been created.'));
} }
$result = mysql_query("SHOW TABLES"); $result = $mysql->query("SHOW TABLES");
while ($row = mysql_fetch_row($result)) { while ($row = $result->fetch_row()) {
if (!mysql_query("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) { if (!$mysql->query("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
break; break;
} }
} }
mysql_free_result($result); $result->free();
if (!$row) { if (!$row) {
mysql_query("DROP DATABASE " . idf_escape($_GET["db"])); $mysql->query("DROP DATABASE " . idf_escape($_GET["db"]));
redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.')); redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
} }
} }
} elseif (!$_POST["collation"] || mysql_query("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'")) { } elseif (!$_POST["collation"] || $mysql->query("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . $mysql->real_escape_string($_POST["collation"]) . "'")) {
redirect(substr($SELF, 0, -1), ($_POST["collation"] ? lang('Database has been altered.') : null)); redirect(substr($SELF, 0, -1), ($_POST["collation"] ? lang('Database has been altered.') : null));
} }
$error = mysql_error(); $error = $mysql->error;
} }
page_header(strlen($_GET["db"]) ? lang('Alter database') . ": " . htmlspecialchars($_GET["db"]) : lang('Create database')); page_header(strlen($_GET["db"]) ? lang('Alter database') . ": " . htmlspecialchars($_GET["db"]) : lang('Create database'));
@ -36,11 +36,11 @@ if ($_POST) {
} else { } else {
$name = $_GET["db"]; $name = $_GET["db"];
$collate = array(); $collate = array();
if (strlen($_GET["db"]) && ($result = mysql_query("SHOW CREATE DATABASE " . idf_escape($_GET["db"])))) { if (strlen($_GET["db"]) && ($result = $mysql->query("SHOW CREATE DATABASE " . idf_escape($_GET["db"])))) {
if (preg_match('~ COLLATE ([^ ]+)~', mysql_result($result, 0, 1), $match)) { if (preg_match('~ COLLATE ([^ ]+)~', $mysql->result($result, 0, 1), $match)) {
$collate = $match[1]; $collate = $match[1];
} }
mysql_free_result($result); $result->free();
} }
} }
?> ?>

View file

@ -16,6 +16,7 @@ H1 { font-size: 150%; margin: 0; }
H2 { font-size: 150%; margin-top: 0; } H2 { font-size: 150%; margin-top: 0; }
FIELDSET { float: left; padding: .5em; margin: 0; } FIELDSET { float: left; padding: .5em; margin: 0; }
PRE { margin: 0; margin: .12em 0; } PRE { margin: 0; margin: .12em 0; }
TABLE { margin-bottom: 1em; }
.error { color: Red; } .error { color: Red; }
.message { color: Green; } .message { color: Green; }
#menu { position: absolute; top: 8px; left: 8px; width: 15em; overflow: auto; white-space: nowrap; } #menu { position: absolute; top: 8px; left: 8px; width: 15em; overflow: auto; white-space: nowrap; }
@ -38,7 +39,7 @@ PRE { margin: 0; margin: .12em 0; }
} }
function page_footer($missing = false) { function page_footer($missing = false) {
global $SELF; global $SELF, $mysql;
?> ?>
</div> </div>
@ -56,30 +57,30 @@ function page_footer($missing = false) {
<select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option> <select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option>
<?php <?php
flush(); flush();
$result = mysql_query("SHOW DATABASES"); $result = $mysql->query("SHOW DATABASES");
while ($row = mysql_fetch_row($result)) { while ($row = $result->fetch_row()) {
echo "<option" . ($row[0] == $_GET["db"] ? " selected='selected'" : "") . ">" . htmlspecialchars($row[0]) . "</option>\n"; echo "<option" . ($row[0] == $_GET["db"] ? " selected='selected'" : "") . ">" . htmlspecialchars($row[0]) . "</option>\n";
} }
mysql_free_result($result); $result->free();
?> ?>
</select><?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value="" /><?php } ?></p> </select><?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value="" /><?php } ?></p>
<noscript><p><input type="submit" value="<?php echo lang('Use'); ?>" /></p></noscript> <noscript><p><input type="submit" value="<?php echo lang('Use'); ?>" /></p></noscript>
</form> </form>
<?php <?php
if ($missing != "db" && strlen($_GET["db"])) { if ($missing != "db" && strlen($_GET["db"])) {
$result = mysql_query("SHOW TABLE STATUS"); $result = $mysql->query("SHOW TABLE STATUS");
if (!mysql_num_rows($result)) { if (!$result->num_rows) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n"; echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else { } else {
echo "<p>\n"; echo "<p>\n";
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> '; echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Engine"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . htmlspecialchars($row["Name"]) . "</a><br />\n"; echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Engine"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . htmlspecialchars($row["Name"]) . "</a><br />\n";
} }
echo "</p>\n"; echo "</p>\n";
} }
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n"; echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
mysql_free_result($result); $result->free();
} }
} }
?> ?>

View file

@ -1,3 +1,3 @@
<?php <?php
header("Content-Type: application/octet-stream"); header("Content-Type: application/octet-stream");
echo mysql_result(mysql_query("SELECT " . idf_escape($_GET["field"]) . " FROM " . idf_escape($_GET["download"]) . " WHERE " . implode(" AND ", where()) . " LIMIT 1"), 0); echo $mysql->result($mysql->query("SELECT " . idf_escape($_GET["field"]) . " FROM " . idf_escape($_GET["download"]) . " WHERE " . implode(" AND ", where()) . " LIMIT 1"), 0);

View file

@ -2,65 +2,63 @@
header("Content-Type: text/plain; charset=utf-8"); header("Content-Type: text/plain; charset=utf-8");
function dump($db) { function dump($db) {
global $mysql;
static $routines; static $routines;
static $version;
if (!isset($routines)) { if (!isset($routines)) {
$version = mysql_get_server_info();
$routines = array(); $routines = array();
if ($version >= 5) { if ($mysql->server_info >= 5) {
foreach (array("FUNCTION", "PROCEDURE") as $routine) { foreach (array("FUNCTION", "PROCEDURE") as $routine) {
$result = mysql_query("SHOW $routine STATUS"); $result = $mysql->query("SHOW $routine STATUS");
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
if (!strlen($_GET["db"]) || $row["Db"] === $_GET["db"]) { if (!strlen($_GET["db"]) || $row["Db"] === $_GET["db"]) {
$routines[$row["Db"]][] = mysql_result(mysql_query("SHOW CREATE $routine " . idf_escape($row["Db"]) . "." . idf_escape($row["Name"])), 0, 2) . ";;\n\n"; $routines[$row["Db"]][] = $mysql->result($mysql->query("SHOW CREATE $routine " . idf_escape($row["Db"]) . "." . idf_escape($row["Name"])), 0, 2) . ";;\n\n";
} }
} }
mysql_free_result($result); $result->free();
} }
} }
} }
$result = mysql_query("SHOW CREATE DATABASE " . idf_escape($db)); $result = $mysql->query("SHOW CREATE DATABASE " . idf_escape($db));
if ($result) { if ($result) {
echo mysql_result($result, 0, 1) . ";\n"; echo $mysql->result($result, 0, 1) . ";\n";
mysql_free_result($result); $result->free();
} }
echo "USE " . idf_escape($db) . ";\n"; echo "USE " . idf_escape($db) . ";\n";
echo "SET CHARACTER SET utf8;\n\n"; echo "SET CHARACTER SET utf8;\n\n";
$result = mysql_query("SHOW TABLE STATUS"); $result = $mysql->query("SHOW TABLE STATUS");
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
$result1 = mysql_query("SHOW CREATE TABLE " . idf_escape($row["Name"])); $result1 = $mysql->query("SHOW CREATE TABLE " . idf_escape($row["Name"]));
if ($result1) { if ($result1) {
echo mysql_result($result1, 0, 1) . ";\n"; echo $mysql->result($result1, 0, 1) . ";\n";
mysql_free_result($result1); $result1->free();
if (isset($row["Engine"])) { if (isset($row["Engine"])) {
$result1 = mysql_query("SELECT * FROM " . idf_escape($row["Name"])); //! enum and set as numbers $result1 = $mysql->query("SELECT * FROM " . idf_escape($row["Name"])); //! enum and set as numbers
if ($result1) { if ($result1) {
while ($row1 = mysql_fetch_row($result1)) { while ($row1 = $result1->fetch_row()) {
echo "INSERT INTO " . idf_escape($row["Name"]) . " VALUES ('" . implode("', '", array_map('mysql_real_escape_string', $row1)) . "');\n"; echo "INSERT INTO " . idf_escape($row["Name"]) . " VALUES ('" . implode("', '", array_map(array($mysql, 'real_escape_string'), $row1)) . "');\n";
} }
mysql_free_result($result1); $result1->free();
} }
} }
echo "\n"; echo "\n";
} }
} }
mysql_free_result($result); $result->free();
if ($version >= 5) { if ($mysql->server_info >= 5) {
$result = mysql_query("SHOW TRIGGERS"); $result = $mysql->query("SHOW TRIGGERS");
$triggers = mysql_num_rows($result); if ($result->num_rows || $routines[$db]) {
if ($triggers || $routines[$db]) {
echo "DELIMITER ;;\n\n"; echo "DELIMITER ;;\n\n";
} }
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n"; echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n";
} }
mysql_free_result($result);
echo implode("", (array) $routines[$db]); echo implode("", (array) $routines[$db]);
if ($triggers || $routines[$db]) { if ($result->num_rows || $routines[$db]) {
echo "DELIMITER ;\n\n"; echo "DELIMITER ;\n\n";
} }
$result->free();
} }
echo "\n\n"; echo "\n\n";
@ -69,13 +67,13 @@ function dump($db) {
if (strlen($_GET["db"])) { if (strlen($_GET["db"])) {
dump($_GET["db"]); dump($_GET["db"]);
} else { } else {
$result = mysql_query("SHOW DATABASES"); $result = $mysql->query("SHOW DATABASES");
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
if ($row["Database"] != "information_schema" || mysql_get_server_info() < 5) { if ($row["Database"] != "information_schema" || $mysql->server_info < 5) {
if (mysql_select_db($row["Database"])) { if ($mysql->select_db($row["Database"])) {
dump($row["Database"]); dump($row["Database"]);
} }
} }
} }
mysql_free_result($result); $result->free();
} }

View file

@ -30,10 +30,10 @@ if ($_POST && !$error) {
$message = lang('Item has been inserted.'); $message = lang('Item has been inserted.');
} }
} }
if (!$set || mysql_query($query)) { if (!$set || $mysql->query($query)) {
redirect($SELF . (isset($_GET["default"]) ? "table=" : ($_POST["insert"] ? "edit=" : "select=")) . urlencode($_GET["edit"]), ($set ? $message : null)); redirect($SELF . (isset($_GET["default"]) ? "table=" : ($_POST["insert"] ? "edit=" : "select=")) . urlencode($_GET["edit"]), ($set ? $message : null));
} }
$error = mysql_error(); $error = $mysql->error;
} }
page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] ? lang('Edit') : lang('Insert'))) . ": " . htmlspecialchars($_GET["edit"])); page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] ? lang('Edit') : lang('Insert'))) . ": " . htmlspecialchars($_GET["edit"]));
@ -50,7 +50,12 @@ if ($_POST) {
$select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name); $select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name);
} }
} }
$data = ($select ? mysql_fetch_assoc(mysql_query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1")) : array()); if ($select) {
$result = $mysql->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1");
$data = $result->fetch_assoc();
} else {
$data = array();
}
} else { } else {
unset($data); unset($data);
} }

View file

@ -30,10 +30,11 @@ function optionlist($options, $selected = array(), $not_vals = false) {
} }
function fields($table) { function fields($table) {
global $mysql;
$return = array(); $return = array();
$result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($table)); $result = $mysql->query("SHOW FULL COLUMNS FROM " . idf_escape($table));
if ($result) { if ($result) {
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match); preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
$return[$row["Field"]] = array( $return[$row["Field"]] = array(
"field" => $row["Field"], "field" => $row["Field"],
@ -48,29 +49,31 @@ function fields($table) {
"comment" => $row["Comment"], "comment" => $row["Comment"],
); );
} }
mysql_free_result($result); $result->free();
} }
return $return; return $return;
} }
function indexes($table) { function indexes($table) {
global $mysql;
$return = array(); $return = array();
$result = mysql_query("SHOW INDEX FROM " . idf_escape($table)); $result = $mysql->query("SHOW INDEX FROM " . idf_escape($table));
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
$return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE"))); $return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
$return[$row["Key_name"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"]; $return[$row["Key_name"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"];
} }
mysql_free_result($result); $result->free();
return $return; return $return;
} }
function foreign_keys($table) { function foreign_keys($table) {
global $mysql;
static $pattern = '~`((?:[^`]*|``)+)`~'; static $pattern = '~`((?:[^`]*|``)+)`~';
$return = array(); $return = array();
$result = mysql_query("SHOW CREATE TABLE " . idf_escape($table)); $result = $mysql->query("SHOW CREATE TABLE " . idf_escape($table));
if ($result) { if ($result) {
$create_table = mysql_result($result, 0, 1); $create_table = $mysql->result($result, 0, 1);
mysql_free_result($result); $result->free();
preg_match_all('~FOREIGN KEY \\((.+)\\) REFERENCES (?:`(.+)`\\.)?`(.+)` \\((.+)\\)~', $create_table, $matches, PREG_SET_ORDER); preg_match_all('~FOREIGN KEY \\((.+)\\) REFERENCES (?:`(.+)`\\.)?`(.+)` \\((.+)\\)~', $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) { foreach ($matches as $match) {
preg_match_all($pattern, $match[1], $source); preg_match_all($pattern, $match[1], $source);
@ -102,9 +105,10 @@ function unique_idf($row, $indexes) {
} }
function where() { function where() {
global $mysql;
$return = array(); $return = array();
foreach ((array) $_GET["where"] as $key => $val) { foreach ((array) $_GET["where"] as $key => $val) {
$return[] = idf_escape(bracket_escape($key, "back")) . " = BINARY '" . mysql_real_escape_string($val) . "'"; //! enum and set $return[] = idf_escape(bracket_escape($key, "back")) . " = BINARY '" . $mysql->real_escape_string($val) . "'"; //! enum and set
} }
foreach ((array) $_GET["null"] as $key) { foreach ((array) $_GET["null"] as $key) {
$return[] = idf_escape(bracket_escape($key, "back")) . " IS NULL"; $return[] = idf_escape(bracket_escape($key, "back")) . " IS NULL";
@ -113,24 +117,26 @@ function where() {
} }
function collations() { function collations() {
global $mysql;
$return = array(); $return = array();
$result = mysql_query("SHOW COLLATION"); $result = $mysql->query("SHOW COLLATION");
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
$return[$row["Charset"]][] = $row["Collation"]; $return[$row["Charset"]][] = $row["Collation"];
} }
mysql_free_result($result); $result->free();
return $return; return $return;
} }
function engines() { function engines() {
global $mysql;
$return = array(); $return = array();
$result = mysql_query("SHOW ENGINES"); $result = $mysql->query("SHOW ENGINES");
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") { if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") {
$return[] = $row["Engine"]; $return[] = $row["Engine"];
} }
} }
mysql_free_result($result); $result->free();
return $return; return $return;
} }
@ -180,11 +186,11 @@ function get_file($key) {
} }
function select($result) { function select($result) {
if (!mysql_num_rows($result)) { if (!$result->num_rows) {
echo "<p class='message'>" . lang('No rows.') . "</p>\n"; echo "<p class='message'>" . lang('No rows.') . "</p>\n";
} else { } else {
echo "<table border='1' cellspacing='0' cellpadding='2'>\n"; echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
for ($i=0; $row = mysql_fetch_row($result); $i++) { for ($i=0; $row = $result->fetch_row(); $i++) {
if (!$i) { if (!$i) {
echo "<thead><tr>"; echo "<thead><tr>";
$links = array(); $links = array();
@ -192,25 +198,24 @@ function select($result) {
$columns = array(); $columns = array();
$blobs = array(); $blobs = array();
for ($j=0; $j < count($row); $j++) { for ($j=0; $j < count($row); $j++) {
$field = mysql_fetch_field($result, $j); $field = $result->fetch_field();
//! table and column aliases if (strlen($field->orgtable) && $field->primary_key) {
if (strlen($field->table) && $field->primary_key) { $links[$j] = $field->orgtable;
$links[$j] = $field->table; if (!isset($indexes[$field->orgtable])) {
if (!isset($indexes[$field->table])) { $indexes[$field->orgtable] = array();
$indexes[$field->table] = array(); foreach (indexes($field->orgtable) as $index) {
foreach (indexes($field->table) as $index) {
if ($index["type"] == "PRIMARY") { if ($index["type"] == "PRIMARY") {
$indexes[$field->table] = array_flip($index["columns"]); $indexes[$field->orgtable] = array_flip($index["columns"]);
break; break;
} }
} }
$columns[$field->table] = $indexes[$field->table]; $columns[$field->orgtable] = $indexes[$field->orgtable];
} }
unset($columns[$field->table][$field->name]); unset($columns[$field->orgtable][$field->orgname]);
$indexes[$field->table][$field->name] = $j; $indexes[$field->orgtable][$field->orgname] = $j;
$links[$j] = $field->table; $links[$j] = $field->orgtable;
} }
if ($field->blob) { if ($field->charsetnr == 63) {
$blobs[$j] = true; $blobs[$j] = true;
} }
echo "<th>" . htmlspecialchars($field->name) . "</th>"; echo "<th>" . htmlspecialchars($field->name) . "</th>";
@ -237,7 +242,7 @@ function select($result) {
} }
echo "</table>\n"; echo "</table>\n";
} }
mysql_free_result($result); $result->free();
} }
function input($name, $field, $value) { function input($name, $field, $value) {
@ -283,22 +288,23 @@ function input($name, $field, $value) {
} }
function process_input($name, $field) { function process_input($name, $field) {
global $mysql;
$name = bracket_escape($name); $name = bracket_escape($name);
$return = $_POST["fields"][$name]; $return = $_POST["fields"][$name];
if (preg_match('~char|text|set|binary|blob~', $field["type"]) ? $_POST["null"][$name] : !strlen($return)) { if (preg_match('~char|text|set|binary|blob~', $field["type"]) ? $_POST["null"][$name] : !strlen($return)) {
$return = "NULL"; $return = "NULL";
} elseif ($field["type"] == "enum") { } elseif ($field["type"] == "enum") {
$return = (isset($_GET["default"]) ? "'" . mysql_real_escape_string($return) . "'" : intval($return)); $return = (isset($_GET["default"]) ? "'" . $mysql->real_escape_string($return) . "'" : intval($return));
} elseif ($field["type"] == "set") { } elseif ($field["type"] == "set") {
$return = (isset($_GET["default"]) ? "'" . implode(",", array_map('mysql_real_escape_string', (array) $return)) . "'" : array_sum((array) $return)); $return = (isset($_GET["default"]) ? "'" . implode(",", array_map(array($mysql, 'real_escape_string'), (array) $return)) . "'" : array_sum((array) $return));
} elseif (preg_match('~binary|blob~', $field["type"])) { } elseif (preg_match('~binary|blob~', $field["type"])) {
$file = get_file($name); $file = get_file($name);
if (!is_string($file) && !$field["null"]) { if (!is_string($file) && !$field["null"]) {
return false; //! report errors, also empty $_POST (too big POST data, not only FILES) return false; //! report errors, also empty $_POST (too big POST data, not only FILES)
} }
$return = "_binary'" . (is_string($file) ? mysql_real_escape_string($file) : "") . "'"; $return = "_binary'" . (is_string($file) ? $mysql->real_escape_string($file) : "") . "'";
} else { } else {
$return = "'" . mysql_real_escape_string($return) . "'"; $return = "'" . $mysql->real_escape_string($return) . "'";
} }
return $return; return $return;
} }

View file

@ -8,6 +8,7 @@ $TOKENS = &$_SESSION["tokens"][$_GET["server"]][preg_replace('~([?&]sql=)upload~
include "./functions.inc.php"; include "./functions.inc.php";
include "./lang.inc.php"; include "./lang.inc.php";
include "./design.inc.php"; include "./design.inc.php";
include "./abstraction.inc.php";
include "./auth.inc.php"; include "./auth.inc.php";
include "./connect.inc.php"; include "./connect.inc.php";
@ -49,12 +50,12 @@ if (isset($_GET["dump"])) {
$TOKENS = array(); $TOKENS = array();
page_header(htmlspecialchars(lang('Database') . ": " . $_GET["db"])); page_header(htmlspecialchars(lang('Database') . ": " . $_GET["db"]));
echo '<p><a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Alter database') . "</a></p>\n"; echo '<p><a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Alter database') . "</a></p>\n";
if (mysql_get_server_info() >= 5) { if ($mysql->server_info >= 5) {
$result = mysql_query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = '" . mysql_real_escape_string($_GET["db"]) . "'"); $result = $mysql->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = '" . $mysql->real_escape_string($_GET["db"]) . "'");
if (mysql_num_rows($result)) { if ($result->num_rows) {
echo "<h2>" . lang('Routines') . "</h2>\n"; echo "<h2>" . lang('Routines') . "</h2>\n";
echo "<table border='0' cellspacing='0' cellpadding='2'>\n"; echo "<table border='0' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
echo "<tr valign='top'>"; echo "<tr valign='top'>";
echo "<th>" . htmlspecialchars($row["ROUTINE_TYPE"]) . "</th>"; echo "<th>" . htmlspecialchars($row["ROUTINE_TYPE"]) . "</th>";
echo '<td><a href="' . htmlspecialchars($SELF) . ($row["ROUTINE_TYPE"] == "FUNCTION" ? 'callf' : 'call') . '=' . urlencode($row["ROUTINE_NAME"]) . '">' . htmlspecialchars($row["ROUTINE_NAME"]) . '</a></td>'; echo '<td><a href="' . htmlspecialchars($SELF) . ($row["ROUTINE_TYPE"] == "FUNCTION" ? 'callf' : 'call') . '=' . urlencode($row["ROUTINE_NAME"]) . '">' . htmlspecialchars($row["ROUTINE_NAME"]) . '</a></td>';
@ -63,7 +64,7 @@ if (isset($_GET["dump"])) {
} }
echo "</table>\n"; echo "</table>\n";
} }
mysql_free_result($result); $result->free();
} }
} }
} }

View file

@ -27,10 +27,10 @@ if ($_POST && !$error && !$_POST["add"]) {
foreach ($indexes as $name => $existing) { foreach ($indexes as $name => $existing) {
$alter[] = "DROP INDEX " . idf_escape($name); $alter[] = "DROP INDEX " . idf_escape($name);
} }
if (!$alter || mysql_query("ALTER TABLE " . idf_escape($_GET["indexes"]) . " " . implode(", ", $alter))) { if (!$alter || $mysql->query("ALTER TABLE " . idf_escape($_GET["indexes"]) . " " . implode(", ", $alter))) {
redirect($SELF . "table=" . urlencode($_GET["indexes"]), ($alter ? lang('Indexes has been altered.') : null)); redirect($SELF . "table=" . urlencode($_GET["indexes"]), ($alter ? lang('Indexes has been altered.') : null));
} }
$error = mysql_error(); $error = $mysql->error;
} }
page_header(lang('Indexes') . ': ' . htmlspecialchars($_GET["indexes"])); page_header(lang('Indexes') . ': ' . htmlspecialchars($_GET["indexes"]));

View file

@ -100,6 +100,8 @@ function lang($idf = null, $number = null) {
'Routine has been called, %d row(s) affected.' => array('Procedura byla zavolána, byl změněn %d záznam.', 'Procedura byla zavolána, byly změněny %d záznamy.', 'Procedura byla zavolána, bylo změněno %d záznamů.'), 'Routine has been called, %d row(s) affected.' => array('Procedura byla zavolána, byl změněn %d záznam.', 'Procedura byla zavolána, byly změněny %d záznamy.', 'Procedura byla zavolána, bylo změněno %d záznamů.'),
'Call' => 'Zavolat', 'Call' => 'Zavolat',
'Error during calling' => 'Chyba při volání', 'Error during calling' => 'Chyba při volání',
'No MySQL extension' => 'Žádná MySQL extenze',
'None of supported PHP extensions (%s) are available.' => 'Není dostupná žádná z podporovaných PHP extenzí (%s).',
), ),
); );
if (!isset($idf)) { if (!isset($idf)) {

View file

@ -15,7 +15,7 @@ if (isset($rights["insert"])) {
} }
if (!$columns) { if (!$columns) {
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . mysql_error()) . ".</p>\n"; echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . $mysql->error) . ".</p>\n";
} else { } else {
$indexes = indexes($_GET["select"]); $indexes = indexes($_GET["select"]);
echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\n"; echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\n";
@ -30,7 +30,7 @@ if (!$columns) {
foreach ($indexes as $i => $index) { foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT") { if ($index["type"] == "FULLTEXT") {
if (strlen($_GET["fulltext"][$i])) { if (strlen($_GET["fulltext"][$i])) {
$where[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST ('" . mysql_real_escape_string($_GET["fulltext"][$i]) . "'" . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")"; $where[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST ('" . $mysql->real_escape_string($_GET["fulltext"][$i]) . "'" . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
} }
echo "(<i>" . implode("</i>, <i>", $index["columns"]) . "</i>) AGAINST"; echo "(<i>" . implode("</i>, <i>", $index["columns"]) . "</i>) AGAINST";
echo ' <input name="fulltext[' . $i . ']" value="' . htmlspecialchars($_GET["fulltext"][$i]) . '" />'; echo ' <input name="fulltext[' . $i . ']" value="' . htmlspecialchars($_GET["fulltext"][$i]) . '" />';
@ -42,7 +42,7 @@ if (!$columns) {
$i = 0; $i = 0;
foreach ((array) $_GET["where"] as $val) { foreach ((array) $_GET["where"] as $val) {
if (strlen($val["col"]) && in_array($val["op"], $operators)) { if (strlen($val["col"]) && in_array($val["op"], $operators)) {
$where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . mysql_real_escape_string($val["val"]) . "'" : ""); $where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . $mysql->real_escape_string($val["val"]) . "'" : "");
echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>"; echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, $val["op"], "not_vals") . "</select>"; echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, $val["op"], "not_vals") . "</select>";
echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /></div>\n"; echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /></div>\n";
@ -90,11 +90,11 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
echo "</form>\n"; echo "</form>\n";
echo "<div style='clear: left; margin-bottom: 1em;'></div>\n"; echo "<div style='clear: left; margin-bottom: 1em;'></div>\n";
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS " . implode(", ", array_map('idf_escape', $columns)) . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : "")); $result = $mysql->query("SELECT SQL_CALC_FOUND_ROWS " . implode(", ", array_map('idf_escape', $columns)) . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : ""));
if (!mysql_num_rows($result)) { if (!$result->num_rows) {
echo "<p class='message'>" . lang('No rows.') . "</p>\n"; echo "<p class='message'>" . lang('No rows.') . "</p>\n";
} else { } else {
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode $found_rows = $mysql->result($mysql->query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
$foreign_keys = array(); $foreign_keys = array();
foreach (foreign_keys($_GET["select"]) as $foreign_key) { foreach (foreign_keys($_GET["select"]) as $foreign_key) {
foreach ($foreign_key[2] as $val) { foreach ($foreign_key[2] as $val) {
@ -102,20 +102,20 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
} }
} }
$childs = array(); $childs = array();
if (mysql_get_server_info() >= 5) { if ($mysql->server_info >= 5) {
// would be possible in earlier versions too, but only by examining all tables (in all databases) // would be possible in earlier versions too, but only by examining all tables (in all databases)
$result1 = mysql_query("SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . mysql_real_escape_string($_GET["db"]) . "' AND REFERENCED_TABLE_NAME = '" . mysql_real_escape_string($_GET["select"]) . "' ORDER BY ORDINAL_POSITION"); $result1 = $mysql->query("SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $mysql->real_escape_string($_GET["db"]) . "' AND REFERENCED_TABLE_NAME = '" . $mysql->real_escape_string($_GET["select"]) . "' ORDER BY ORDINAL_POSITION");
while ($row1 = mysql_fetch_assoc($result1)) { while ($row1 = $result1->fetch_assoc()) {
$childs[$row1["CONSTRAINT_NAME"]][0] = $row1["TABLE_SCHEMA"]; $childs[$row1["CONSTRAINT_NAME"]][0] = $row1["TABLE_SCHEMA"];
$childs[$row1["CONSTRAINT_NAME"]][1] = $row1["TABLE_NAME"]; $childs[$row1["CONSTRAINT_NAME"]][1] = $row1["TABLE_NAME"];
$childs[$row1["CONSTRAINT_NAME"]][2][] = $row1["REFERENCED_COLUMN_NAME"]; $childs[$row1["CONSTRAINT_NAME"]][2][] = $row1["REFERENCED_COLUMN_NAME"];
$childs[$row1["CONSTRAINT_NAME"]][3][] = $row1["COLUMN_NAME"]; $childs[$row1["CONSTRAINT_NAME"]][3][] = $row1["COLUMN_NAME"];
} }
mysql_free_result($result1); $result1->free();
} }
echo "<table border='1' cellspacing='0' cellpadding='2'>\n"; echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
for ($j=0; $row = mysql_fetch_assoc($result); $j++) { for ($j=0; $row = $result->fetch_assoc(); $j++) {
if (!$j) { if (!$j) {
echo "<thead><tr><th>" . implode("</th><th>", array_map('htmlspecialchars', array_keys($row))) . "</th><th>" . lang('Action') . "</th></tr></thead>\n"; echo "<thead><tr><th>" . implode("</th><th>", array_map('htmlspecialchars', array_keys($row))) . "</th><th>" . lang('Action') . "</th></tr></thead>\n";
} }
@ -161,5 +161,5 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
echo "</p>\n"; echo "</p>\n";
} }
} }
mysql_free_result($result); $result->free();
} }

View file

@ -18,21 +18,20 @@ if ($_POST && $error) {
} else { } else {
$empty = false; $empty = false;
echo "<pre class='jush-sql'>" . htmlspecialchars(substr($query, 0, $match[0][1])) . "</pre>\n"; echo "<pre class='jush-sql'>" . htmlspecialchars(substr($query, 0, $match[0][1])) . "</pre>\n";
$result = mysql_query(substr($query, 0, $match[0][1])); if (!$mysql->multi_query(substr($query, 0, $match[0][1]))) {
echo "<p class='error'>" . lang('Error in query') . ": " . htmlspecialchars($mysql->error) . "</p>\n";
} else{
do {
$result = $mysql->store_result();
if (is_object($result)) {
select($result);
} else {
echo "<p class='message'>" . lang('Query executed OK, %d row(s) affected.', $mysql->affected_rows) . "</p>\n";
}
} while ($mysql->next_result());
}
$query = substr($query, $match[0][1] + strlen($match[0][0])); $query = substr($query, $match[0][1] + strlen($match[0][0]));
$offset = 0; $offset = 0;
if (!$result) {
echo "<p class='error'>" . lang('Error in query') . ": " . htmlspecialchars(mysql_error()) . "</p>\n";
} elseif ($result === true) {
/* more secure but less user-friendly
if (token_delete()) {
$token = token();
}
*/
echo "<p class='message'>" . lang('Query executed OK, %d row(s) affected.', mysql_affected_rows()) . "</p>\n";
} else {
select($result);
}
} }
} }
} }

View file

@ -1,20 +1,20 @@
<?php <?php
page_header(lang('Table') . ": " . htmlspecialchars($_GET["table"])); page_header(lang('Table') . ": " . htmlspecialchars($_GET["table"]));
$result = mysql_query("SHOW COLUMNS FROM " . idf_escape($_GET["table"])); $result = $mysql->query("SHOW COLUMNS FROM " . idf_escape($_GET["table"]));
if (!$result) { if (!$result) {
echo "<p class='error'>" . lang('Unable to show the table definition') . ": " . mysql_error() . ".</p>\n"; echo "<p class='error'>" . lang('Unable to show the table definition') . ": " . $mysql->error . ".</p>\n";
} else { } else {
$auto_increment_only = true; $auto_increment_only = true;
echo "<table border='1' cellspacing='0' cellpadding='2'>\n"; echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
if (!$row["auto_increment"]) { if (!$row["auto_increment"]) {
$auto_increment_only = false; $auto_increment_only = false;
} }
echo "<tr><th>" . htmlspecialchars($row["Field"]) . "</th><td>$row[Type]" . ($row["Null"] == "YES" ? " <i>NULL</i>" : "") . "</td></tr>\n"; echo "<tr><th>" . htmlspecialchars($row["Field"]) . "</th><td>$row[Type]" . ($row["Null"] == "YES" ? " <i>NULL</i>" : "") . "</td></tr>\n";
} }
echo "</table>\n"; echo "</table>\n";
mysql_free_result($result); $result->free();
echo "<p>"; echo "<p>";
echo '<a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . '</a>'; echo '<a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . '</a>';
@ -44,15 +44,15 @@ if (!$result) {
} }
} }
if (mysql_get_server_info() >= 5) { if ($mysql->server_info >= 5) {
$result = mysql_query("SHOW TRIGGERS LIKE '" . mysql_real_escape_string($_GET["table"]) . "'"); $result = $mysql->query("SHOW TRIGGERS LIKE '" . $mysql->real_escape_string($_GET["table"]) . "'");
if (mysql_num_rows($result)) { if ($result->num_rows) {
echo "<h3>" . lang('Triggers') . "</h3>\n"; echo "<h3>" . lang('Triggers') . "</h3>\n";
echo "<table border='0' cellspacing='0' cellpadding='2'>\n"; echo "<table border='0' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_assoc()) {
echo "<tr valign='top'><th>$row[Timing]</th><th>$row[Event]</th><td><pre class='jush-sql'>" . htmlspecialchars($row["Statement"]) . "</pre></td></tr>\n"; echo "<tr valign='top'><th>$row[Timing]</th><th>$row[Event]</th><td><pre class='jush-sql'>" . htmlspecialchars($row["Statement"]) . "</pre></td></tr>\n";
} }
echo "</table>\n"; echo "</table>\n";
} }
mysql_free_result($result); $result->free();
} }

View file

@ -1,3 +1,3 @@
<?php <?php
page_header(lang('View') . ": " . htmlspecialchars($_GET["view"])); page_header(lang('View') . ": " . htmlspecialchars($_GET["view"]));
echo "<pre class='jush-sql'>" . htmlspecialchars(preg_replace('~^.* AS ~U', '', mysql_result(mysql_query("SHOW CREATE VIEW " . idf_escape($_GET["view"])), 0, 1))) . "</pre>\n"; echo "<pre class='jush-sql'>" . htmlspecialchars(preg_replace('~^.* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($_GET["view"])), 0, 1))) . "</pre>\n";