Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use separate connection for exploring indexes

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@649 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
commit fbebb08722090f25eae91b177ad9edc69203dc77 1 parent d2dfc5a
jakubvrana authored
2  _compile.php
View
@@ -76,7 +76,7 @@ function php_shrink($input) {
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
static $short_variables = array();
$shortening = true;
- $special_functions = array_flip(array('Min_MySQLi', 'Min_MySQLResult', '__construct'));
+ $special_functions = array_flip(array('Min_DB', 'Min_Result', '__construct'));
$defined_functions = array();
static $short_functions = array();
$tokens = token_get_all($input);
6 include/functions.inc.php
View
@@ -143,7 +143,7 @@ function odd($s = ' class="odd"') {
return ($i++ % 2 ? $s : '');
}
-function select($result) {
+function select($result, $dbh2 = null) {
global $SELF;
if (!$result->num_rows) {
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
@@ -163,7 +163,7 @@ function select($result) {
if (strlen($field->orgtable)) {
if (!isset($indexes[$field->orgtable])) {
$indexes[$field->orgtable] = array();
- foreach (indexes($field->orgtable) as $index) {
+ foreach (indexes($field->orgtable, $dbh2) as $index) {
if ($index["type"] == "PRIMARY") {
$indexes[$field->orgtable] = array_flip($index["columns"]);
break;
@@ -193,7 +193,7 @@ function select($result) {
if ($blobs[$key] && preg_match('~[\\x80-\\xFF]~', $val)) {
$val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>";
} else {
- $val = (strlen(trim($val)) ? nl2br(htmlspecialchars($val)) : "&nbsp;");
+ $val = nl2br(htmlspecialchars($val));
if ($types[$key] == 254) {
$val = "<code>$val</code>";
}
43 include/mysql.inc.php
View
@@ -1,10 +1,10 @@
<?php
if (extension_loaded("mysqli")) {
- class Min_MySQLi extends MySQLi {
+ class Min_DB extends MySQLi {
var $extension = "MySQLi";
- function Min_MySQLi() {
- $this->init();
+ function Min_DB() {
+ parent::init();
}
function connect($server, $username, $password) {
@@ -34,7 +34,7 @@ function select_db($database) {
function query($query) {
$result = parent::query($query);
- return (is_object($result) ? new Min_MySQLiResult($result) : $result);
+ return (is_object($result) ? new Min_Result($result) : $result);
}
function multi_query($query) {
@@ -43,7 +43,7 @@ function multi_query($query) {
function store_result() {
$result = parent::store_result();
- return (is_object($result) ? new Min_MySQLiResult($result) : $result);
+ return (is_object($result) ? new Min_Result($result) : $result);
}
function next_result() {
@@ -55,7 +55,7 @@ function escape_string($string) {
}
}
- class Min_MySQLiResult {
+ class Min_Result {
var $_result, $num_rows;
function __construct($result) {
@@ -81,10 +81,8 @@ function free() {
// minification compatibility end
}
- $dbh = new Min_MySQLi;
-
} elseif (extension_loaded("mysql")) {
- class Min_MySQL {
+ class Min_DB {
var $extension = "MySQL", $_link, $_result, $server_info, $affected_rows, $error;
function connect($server, $username, $password) {
@@ -92,10 +90,13 @@ function connect($server, $username, $password) {
(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")),
+ true,
131072 // CLIENT_MULTI_RESULTS for CALL
);
if ($this->_link) {
$this->server_info = mysql_get_server_info($this->_link);
+ } else {
+ $this->error = mysql_error();
}
return (bool) $this->_link;
}
@@ -113,7 +114,7 @@ function query($query) {
$this->affected_rows = mysql_affected_rows($this->_link);
return true;
}
- return new Min_MySQLResult($result);
+ return new Min_Result($result);
}
function multi_query($query) {
@@ -140,10 +141,10 @@ function escape_string($string) {
}
}
- class Min_MySQLResult {
+ class Min_Result {
var $_result, $_offset = 0, $num_rows;
- function Min_MySQLResult($result) {
+ function Min_Result($result) {
$this->_result = $result;
$this->num_rows = mysql_num_rows($result);
}
@@ -169,10 +170,8 @@ function free() {
}
}
- $dbh = new Min_MySQL;
-
} elseif (extension_loaded("pdo_mysql")) {
- class Min_PDO_MySQL extends Min_PDO {
+ class Min_DB extends Min_PDO {
var $extension = "PDO_MySQL";
function connect($server, $username, $password) {
@@ -182,8 +181,6 @@ function connect($server, $username, $password) {
}
}
- $dbh = new Min_PDO_MySQL;
-
} else {
page_header(lang('No MySQL extension'), lang('None of supported PHP extensions (%s) are available.', 'MySQLi, MySQL, PDO_MySQL'), null);
page_footer("auth");
@@ -202,6 +199,11 @@ function connect($server, $username, $password) {
);
$unsigned = array("", "unsigned", "zerofill", "unsigned zerofill");
+function connect() {
+ $dbh = new Min_DB;
+ return ($dbh->connect($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]) ? $dbh : $dbh->error);
+}
+
function get_databases() {
$return = &$_SESSION["databases"][$_GET["server"]];
if (!isset($return)) {
@@ -245,10 +247,13 @@ function fields($table) {
return $return;
}
-function indexes($table) {
+function indexes($table, $dbh2 = null) {
global $dbh;
+ if (!is_object($dbh2)) {
+ $dbh2 = $dbh;
+ }
$return = array();
- $result = $dbh->query("SHOW INDEX FROM " . idf_escape($table));
+ $result = $dbh2->query("SHOW INDEX FROM " . idf_escape($table));
if ($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")));
31 include/sqlite.inc.php
View
@@ -2,7 +2,7 @@
if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
if ($_GET["sqlite_version"] == 2) {
- class SQLite extends SQLiteDatabase {
+ class Min_SQLite extends SQLiteDatabase {
var $extension = "SQLite";
function open($filename) {
@@ -18,7 +18,7 @@ function query($query) {
$this->affected_rows = parent::changes();
return true;
}
- return new Min_SQLiteResult($result);
+ return new Min_Result($result);
}
function escape_string($string) {
@@ -34,7 +34,7 @@ function result($result, $field = 0) {
}
}
- class Min_SQLiteResult {
+ class Min_Result {
var $_result, $num_rows;
function __construct($result) {
@@ -65,7 +65,7 @@ function free() {
} else {
- class SQLite extends SQLite3 {
+ class Min_SQLite extends SQLite3 {
var $extension = "SQLite3";
function open($filename) {
@@ -81,7 +81,7 @@ function query($query) {
$this->affected_rows = parent::changes();
return true;
}
- return new Min_SQLiteResult($result);
+ return new Min_Result($result);
}
function escape_string($string) {
@@ -97,7 +97,7 @@ function result($result, $field = 0) {
}
}
- class Min_SQLiteResult {
+ class Min_Result {
var $_result, $num_rows;
function __construct($result) {
@@ -130,14 +130,11 @@ function free() {
}
- class Min_SQLite extends SQLite {
+ class Min_DB extends Min_SQLite {
function __construct() {
}
- function connect() {
- }
-
function select_db($filename) {
set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
$this->open($filename);
@@ -160,11 +157,8 @@ function next_result() {
}
} elseif (extension_loaded("pdo_sqlite")) {
- class Min_PDO_MySQL extends Min_PDO {
- var $extension = "PDO_MySQL";
-
- function connect() {
- }
+ class Min_DB extends Min_PDO {
+ var $extension = "PDO_SQLite";
function select_db($filename) {
set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
@@ -176,12 +170,15 @@ function select_db($filename) {
}
}
- $dbh = new Min_PDO_SQLite;
}
$types = array("text" => 0, "numeric" => 0, "integer" => 0, "real" => 0, "blob" => 0);
$unsigned = array();
+function connect() {
+ return new Min_DB;
+}
+
function get_databases() {
return array();
}
@@ -212,7 +209,7 @@ function fields($table) {
return $return;
}
-function indexes($table) {
+function indexes($table, $dbh2 = null) {
global $dbh;
$return = array();
$result = $dbh->query("PRAGMA index_list(" . idf_escape($table) . ")");
6 sql.inc.php
View
@@ -13,6 +13,10 @@
$offset = 0;
$empty = true;
$space = "(\\s+|/\\*.*\\*/|(#|-- )[^\n]*\n|--\n)";
+ $dbh2 = (strlen($_GET["db"]) ? connect() : null); // connection for exploring indexes (to not replace FOUND_ROWS()) //! PDO - silent error
+ if (is_object($dbh2)) {
+ $dbh2->select_db($_GET["db"]);
+ }
while (rtrim($query)) {
if (!$offset && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) {
$delimiter = $match[1];
@@ -39,7 +43,7 @@
do {
$result = $dbh->store_result();
if (is_object($result)) {
- select($result);
+ select($result, $dbh2);
} else {
if (preg_match("~^$space*(CREATE|DROP)$space+(DATABASE|SCHEMA)\\b~isU", $query)) {
unset($_SESSION["databases"][$_GET["server"]]);
Please sign in to comment.
Something went wrong with that request. Please try again.