diff --git a/_compile.php b/_compile.php index bb4f7bef..cc2bdf96 100644 --- a/_compile.php +++ b/_compile.php @@ -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); diff --git a/include/functions.inc.php b/include/functions.inc.php index 43de2819..ada6b22c 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -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 "
\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 = "" . lang('%d byte(s)', strlen($val)) . ""; } else { - $val = (strlen(trim($val)) ? nl2br(htmlspecialchars($val)) : " "); + $val = nl2br(htmlspecialchars($val)); if ($types[$key] == 254) { $val = "$val
";
}
diff --git a/include/mysql.inc.php b/include/mysql.inc.php
index 5d1a0083..68767250 100644
--- a/include/mysql.inc.php
+++ b/include/mysql.inc.php
@@ -1,10 +1,10 @@
init();
+ function Min_DB() {
+ parent::init();
}
function connect($server, $username, $password) {
@@ -34,7 +34,7 @@ if (extension_loaded("mysqli")) {
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 @@ if (extension_loaded("mysqli")) {
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 @@ if (extension_loaded("mysqli")) {
}
}
- class Min_MySQLiResult {
+ class Min_Result {
var $_result, $num_rows;
function __construct($result) {
@@ -81,10 +81,8 @@ if (extension_loaded("mysqli")) {
// 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 @@ if (extension_loaded("mysqli")) {
(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 @@ if (extension_loaded("mysqli")) {
$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 @@ if (extension_loaded("mysqli")) {
}
}
- 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 @@ if (extension_loaded("mysqli")) {
}
}
- $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 @@ if (extension_loaded("mysqli")) {
}
}
- $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 @@ $types = array(
);
$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")));
diff --git a/include/sqlite.inc.php b/include/sqlite.inc.php
index 2a31ad95..156d3198 100644
--- a/include/sqlite.inc.php
+++ b/include/sqlite.inc.php
@@ -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 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
$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 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
}
}
- class Min_SQLiteResult {
+ class Min_Result {
var $_result, $num_rows;
function __construct($result) {
@@ -65,7 +65,7 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
} else {
- class SQLite extends SQLite3 {
+ class Min_SQLite extends SQLite3 {
var $extension = "SQLite3";
function open($filename) {
@@ -81,7 +81,7 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
$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 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
}
}
- class Min_SQLiteResult {
+ class Min_Result {
var $_result, $num_rows;
function __construct($result) {
@@ -130,14 +130,11 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
}
- 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 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
}
} 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 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
}
}
- $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) . ")");
diff --git a/sql.inc.php b/sql.inc.php
index 920eeefd..452108bf 100644
--- a/sql.inc.php
+++ b/sql.inc.php
@@ -13,6 +13,10 @@ if (!$error && $_POST) {
$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 @@ if (!$error && $_POST) {
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"]]);