diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 3fc2c0a8..7df9d79a 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -38,7 +38,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { ksort($row["fields"]); $orig_field = reset($orig_fields); $after = " FIRST"; - + foreach ($row["fields"] as $key => $field) { $foreign_key = $foreign_keys[$field["type"]]; $type_field = ($foreign_key !== null ? $referencable_primary[$foreign_key] : $field); //! can collide with user defined type @@ -58,7 +58,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { } } if ($foreign_key !== null) { - $foreign[idf_escape($field["field"])] = ($TABLE != "" && $jush != "sqlite" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (ereg("^($on_actions)\$", $field["on_delete"]) ? " ON DELETE $field[on_delete]" : ""); + $foreign[idf_escape($field["field"])] = ($TABLE != "" && $jush != "sqlite" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (preg_match("~^($on_actions)\$~", $field["on_delete"]) ? " ON DELETE $field[on_delete]" : ""); } $after = " AFTER " . idf_escape($field["field"]); } elseif ($field["orig"] != "") { @@ -72,7 +72,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { } } } - + $partitioning = ""; if ($partition_by[$row["partition_by"]]) { $partitions = array(); @@ -86,17 +86,17 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { ? " (" . implode(",", $partitions) . "\n)" : ($row["partitions"] ? " PARTITIONS " . (+$row["partitions"]) : "") ); - } elseif (support("partitioning") && ereg("partitioned", $table_status["Create_options"])) { + } elseif (support("partitioning") && preg_match("~partitioned~", $table_status["Create_options"])) { $partitioning .= "\nREMOVE PARTITIONING"; } - + $message = lang('Table has been altered.'); if ($TABLE == "") { cookie("adminer_engine", $row["Engine"]); $message = lang('Table has been created.'); } $name = trim($row["name"]); - + queries_redirect(ME . (support("table") ? "table=" : "select=") . urlencode($name), $message, alter_table( $TABLE, $name, @@ -119,7 +119,7 @@ if (!$_POST) { "fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))), "partition_names" => array(""), ); - + if ($TABLE != "") { $row = $table_status; $row["name"] = $TABLE; @@ -131,7 +131,7 @@ if (!$_POST) { $field["has_default"] = isset($field["default"]); $row["fields"][] = $field; } - + if (support("partitioning")) { $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($TABLE); $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1"); @@ -161,7 +161,7 @@ foreach ($engines as $engine) { : " autocapitalize="off"> " . optionlist(array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) . "" : ""); ?> - "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?> + "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?> @@ -196,7 +196,7 @@ edit_fields($row["fields"], $collations, "TABLE", $foreign_keys, $comments); >
diff --git a/adminer/database.inc.php b/adminer/database.inc.php
index c77a67d0..b0f5db6c 100644
--- a/adminer/database.inc.php
+++ b/adminer/database.inc.php
@@ -31,7 +31,7 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c
if (!$row["collation"]) {
redirect(substr(ME, 0, -1));
}
- query_redirect("ALTER DATABASE " . idf_escape($name) . (eregi('^[a-z0-9_]+$', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.'));
+ query_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.'));
}
}
diff --git a/adminer/db.inc.php b/adminer/db.inc.php
index c81a8c93..4fae3bad 100644
--- a/adminer/db.inc.php
+++ b/adminer/db.inc.php
@@ -7,7 +7,7 @@ if ($tables_views && !$error && !$_POST["search"]) {
if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"] || $_POST["copy"])) {
queries("SET foreign_key_checks = 0"); // allows to truncate or drop several tables at once
}
-
+
if ($_POST["truncate"]) {
if ($_POST["tables"]) {
$result = truncate_tables($_POST["tables"]);
@@ -40,7 +40,7 @@ if ($tables_views && !$error && !$_POST["search"]) {
$message .= "" . h($row["Table"]) . ": " . h($row["Msg_text"]) . "
";
}
}
-
+
queries_redirect(substr(ME, 0, -1), $message, $result);
}
@@ -63,7 +63,7 @@ if ($adminer->homepage()) {
}
}
echo "
'; echo ' | ' . lang('Table'); echo ' | ' . lang('Engine'); @@ -75,10 +75,10 @@ if ($adminer->homepage()) { echo ' | ' . lang('Rows'); echo (support("comment") ? ' | ' . lang('Comment') : ''); echo " |
---|---|---|---|---|
' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');"); echo ' | ' . (support("table") ? '' . h($name) . '' : h($name)); if ($view) { @@ -104,14 +104,14 @@ if ($adminer->homepage()) { } echo (support("comment") ? " | " : ""); } - + echo " | ||
" . lang('%d in total', count($tables_list)); echo " | " . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : ""); echo " | " . nbsp(db_collation(DB, collations())); foreach (array("Data_length", "Index_length", "Data_free") as $key) { echo " | "; } - + echo " |
' . lang('Create table') . "\n"; echo (support("view") ? '' . lang('Create view') . "\n" : ""); - + if (support("routine")) { echo "
" . lang('Create sequence') . "\n"; } - + if (support("type")) { echo "
" . lang('Create type') . "\n"; } - + if (support("event")) { echo "
' . lang('Create event') . "\n"; } - + if ($tables_list) { echo "\n"; } diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php index a7f68b83..5808e93f 100644 --- a/adminer/drivers/elastic.inc.php +++ b/adminer/drivers/elastic.inc.php @@ -4,11 +4,11 @@ $drivers["elastic"] = "Elasticsearch"; if (isset($_GET["elastic"])) { $possible_drivers = array("json"); define("DRIVER", "elastic"); - + if (function_exists('json_decode')) { class Min_DB { var $extension = "JSON", $server_info, $errno, $error, $_url; - + function query($path) { @ini_set('track_errors', 1); // @ - may be disabled $file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array( @@ -18,7 +18,7 @@ if (isset($_GET["elastic"])) { $this->error = $php_errormsg; return $file; } - if (!eregi('^HTTP/[0-9.]+ 2', $http_response_header[0])) { + if (!preg_match('~^HTTP/[0-9.]+ 2~i', $http_response_header[0])) { $this->error = $file; return false; } @@ -30,7 +30,7 @@ if (isset($_GET["elastic"])) { } else { $constants = get_defined_constants(true); foreach ($constants['json'] as $name => $value) { - if ($value == $this->errno && ereg('^JSON_ERROR_', $name)) { + if ($value == $this->errno && preg_match('~^JSON_ERROR_~', $name)) { $this->error = $name; break; } @@ -39,7 +39,7 @@ if (isset($_GET["elastic"])) { } return $return; } - + function connect($server, $username, $password) { $this->_url = "http://$username:$password@$server/"; $return = $this->query(''); @@ -48,51 +48,51 @@ if (isset($_GET["elastic"])) { } return (bool) $return; } - + function select_db($database) { $this->_db = $database; return true; } - + function quote($string) { return $string; } - + } - + class Min_Result { var $_rows; - + function Min_Result($rows) { $this->_rows = $rows; reset($this->_rows); } - + function fetch_assoc() { $return = current($this->_rows); next($this->_rows); return $return; } - + function fetch_row() { return array_values($this->fetch_assoc()); } - + } - + } - - - + + + class Min_Driver extends Min_SQL { - + function select($table, $select, $where, $group, $order, $limit, $page) { global $adminer; $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page); if (!$query) { $query = "$table/_search?default_operator=AND" . ($select != array("*") ? "&fields=" . urlencode(implode(",", $select)) : "") - . ($order ? "&sort=" . urlencode(ereg_replace(' DESC(,|$)', ':desc\1', implode(",", $order))) : "") + . ($order ? "&sort=" . urlencode(preg_replace('~ DESC(,|$)~', ':desc\1', implode(",", $order))) : "") . ($limit ? "&size=" . (+$limit) . ($page ? "&from=" . ($page * $limit) : "") : "") // doesn't support returning all results ; foreach ((array) $_GET["where"] as $val) { @@ -124,11 +124,11 @@ if (isset($_GET["elastic"])) { } return new Min_Result($return); } - + } - - - + + + function connect() { global $adminer; $connection = new Min_DB; @@ -138,17 +138,17 @@ if (isset($_GET["elastic"])) { } return $connection->error; } - + function support($feature) { - return ereg("database|table", $feature); + return preg_match("~database|table~", $feature); } - + function logged_user() { global $adminer; $credentials = $adminer->credentials(); return $credentials[1]; } - + function get_databases() { global $connection; $return = $connection->query('_aliases'); @@ -157,14 +157,14 @@ if (isset($_GET["elastic"])) { } return $return; } - + function collations() { return array(); } - + function db_collation($db, $collations) { } - + function count_tables($databases) { global $connection; $return = $connection->query('_mapping'); @@ -173,7 +173,7 @@ if (isset($_GET["elastic"])) { } return $return; } - + function tables_list() { global $connection; $return = $connection->query('_mapping'); @@ -182,7 +182,7 @@ if (isset($_GET["elastic"])) { } return $return; } - + function table_status($name = "", $fast = false) { $return = tables_list(); if ($return) { @@ -195,24 +195,24 @@ if (isset($_GET["elastic"])) { } return $return; } - + function error() { global $connection; return h($connection->error); } - + function information_schema() { } - + function is_view($table_status) { } - + function indexes($table, $connection2 = null) { return array( array("type" => "PRIMARY", "columns" => array("_id")), ); } - + function fields($table) { global $connection; $mapping = $connection->query("$table/_mapping"); @@ -229,33 +229,33 @@ if (isset($_GET["elastic"])) { } return $return; } - + function foreign_keys($table) { return array(); } - + function table($idf) { return $idf; } - + function idf_escape($idf) { return $idf; } - + function convert_field($field) { } - + function unconvert_field($field, $return) { return $return; } - + function fk_support($table_status) { } - + function found_rows($table_status, $where) { return null; } - + $jush = "elastic"; $operators = array("="); $functions = array(); diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index 77a24975..162709f5 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -104,7 +104,7 @@ if (isset($_GET["mssql"])) { } return $row; } - + function fetch_assoc() { return $this->_convert(sqlsrv_fetch_array($this->_result, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_NEXT)); } @@ -124,7 +124,7 @@ if (isset($_GET["mssql"])) { $return->type = ($field["Type"] == 1 ? 254 : 0); return $return; } - + function seek($offset) { for ($i=0; $i < $offset; $i++) { sqlsrv_fetch($this->_result); // SQLSRV_SCROLL_ABSOLUTE added in sqlsrv 1.1 @@ -135,7 +135,7 @@ if (isset($_GET["mssql"])) { sqlsrv_free_stmt($this->_result); } } - + } elseif (extension_loaded("mssql")) { class Min_DB { var $extension = "MSSQL", $_link, $_result, $server_info, $affected_rows, $error; @@ -225,18 +225,18 @@ if (isset($_GET["mssql"])) { function seek($offset) { mssql_data_seek($this->_result, $offset); } - + function __destruct() { mssql_free_result($this->_result); } } - + } class Min_Driver extends Min_SQL { - + function insertUpdate($table, $rows, $primary) { foreach ($rows as $set) { $update = array(); @@ -257,11 +257,11 @@ if (isset($_GET["mssql"])) { } return true; } - + function begin() { return queries("BEGIN TRANSACTION"); } - + } @@ -323,7 +323,7 @@ if (isset($_GET["mssql"])) { } return $return; } - + function table_status($name = "") { $return = array(); foreach (get_rows("SELECT name AS Name, type_desc AS Engine FROM sys.all_objects WHERE schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND type IN ('S', 'U', 'V') " . ($name != "" ? "AND name = " . q($name) : "ORDER BY name")) as $row) { @@ -338,7 +338,7 @@ if (isset($_GET["mssql"])) { function is_view($table_status) { return $table_status["Engine"] == "VIEW"; } - + function fk_support($table_status) { return true; } @@ -353,7 +353,7 @@ LEFT JOIN sys.default_constraints d ON c.default_object_id = d.parent_column_id WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U', 'V') AND o.name = " . q($table) ) as $row) { $type = $row["type"]; - $length = (ereg("char|binary", $type) ? $row["max_length"] : ($type == "decimal" ? "$row[precision],$row[scale]" : "")); + $length = (preg_match("~char|binary~", $type) ? $row["max_length"] : ($type == "decimal" ? "$row[precision],$row[scale]" : "")); $return[$row["name"]] = array( "field" => $row["name"], "full_type" => $type . ($length ? "($length)" : ""), @@ -392,11 +392,11 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table) global $connection; return array("select" => preg_replace('~^(?:[^[]|\\[[^]]*])*\\s+AS\\s+~isU', '', $connection->result("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = SCHEMA_NAME() AND TABLE_NAME = " . q($name)))); } - + function collations() { $return = array(); foreach (get_vals("SELECT name FROM fn_helpcollations()") as $collation) { - $return[ereg_replace("_.*", "", $collation)][] = $collation; + $return[preg_replace('~_.*~', '', $collation)][] = $collation; } return $return; } @@ -409,17 +409,17 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table) global $connection; return nl_br(h(preg_replace('~^(\\[[^]]*])+~m', '', $connection->error))); } - + function create_database($db, $collation) { - return queries("CREATE DATABASE " . idf_escape($db) . (eregi('^[a-z0-9_]+$', $collation) ? " COLLATE $collation" : "")); + return queries("CREATE DATABASE " . idf_escape($db) . (preg_match('~^[a-z0-9_]+$~i', $collation) ? " COLLATE $collation" : "")); } - + function drop_databases($databases) { return queries("DROP DATABASE " . implode(", ", array_map('idf_escape', $databases))); } - + function rename_database($name, $collation) { - if (eregi('^[a-z0-9_]+$', $collation)) { + if (preg_match('~^[a-z0-9_]+$~i', $collation)) { queries("ALTER DATABASE " . idf_escape(DB) . " COLLATE $collation"); } queries("ALTER DATABASE " . idf_escape(DB) . " MODIFY NAME = " . idf_escape($name)); @@ -429,7 +429,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table) function auto_increment() { return " IDENTITY" . ($_POST["Auto_increment"] != "" ? "(" . (+$_POST["Auto_increment"]) . ",1)" : "") . " PRIMARY KEY"; } - + function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { $alter = array(); foreach ($fields as $field) { @@ -466,7 +466,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table) } return true; } - + function alter_indexes($table, $alter) { $index = array(); $drop = array(); @@ -488,22 +488,22 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table) && (!$drop || queries("ALTER TABLE " . table($table) . " DROP " . implode(", ", $drop))) ; } - + function last_id() { global $connection; return $connection->result("SELECT SCOPE_IDENTITY()"); // @@IDENTITY can return trigger INSERT } - + function explain($connection, $query) { $connection->query("SET SHOWPLAN_ALL ON"); $return = $connection->query($query); $connection->query("SET SHOWPLAN_ALL OFF"); // connection is used also for indexes return $return; } - + function found_rows($table_status, $where) { } - + function foreign_keys($table) { $return = array(); foreach (get_rows("EXEC sp_fkeys @fktable_name = " . q($table)) as $row) { @@ -530,7 +530,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table) function move_tables($tables, $views, $target) { return apply_queries("ALTER SCHEMA " . idf_escape($target) . " TRANSFER", array_merge($tables, $views)); } - + function trigger($name) { if ($name == "") { return array(); @@ -549,7 +549,7 @@ WHERE s.xtype = 'TR' AND s.name = " . q($name) } return $return; } - + function triggers($table) { $return = array(); foreach (get_rows("SELECT sys1.name, @@ -563,18 +563,18 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table) } return $return; } - + function trigger_options() { return array( "Timing" => array("AFTER", "INSTEAD OF"), "Type" => array("AS"), ); } - + function schemas() { return get_vals("SELECT name FROM sys.schemas"); } - + function get_schema() { global $connection; if ($_GET["ns"] != "") { @@ -582,34 +582,34 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table) } return $connection->result("SELECT SCHEMA_NAME()"); } - + function set_schema($schema) { return true; // ALTER USER is permanent } - + function use_sql($database) { return "USE " . idf_escape($database); } - + function show_variables() { return array(); } - + function show_status() { return array(); } function convert_field($field) { } - + function unconvert_field($field, $return) { return $return; } - + function support($feature) { - return ereg('^(database|table|sql|indexes|scheme|trigger|view|drop_col)$', $feature); //! routine| + return preg_match('~^(database|table|sql|indexes|scheme|trigger|view|drop_col)$~', $feature); //! routine| } - + $jush = "mssql"; $types = array(); $structured_types = array(); diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 89a3cccc..cbba07e2 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -8,11 +8,11 @@ if (!defined("DRIVER")) { if (extension_loaded("mysqli")) { class Min_DB extends MySQLi { var $extension = "MySQLi"; - + function Min_DB() { parent::init(); } - + function connect($server, $username, $password) { mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4 list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket @@ -33,7 +33,7 @@ if (!defined("DRIVER")) { } return $return; } - + function result($query, $field = 0) { $result = $this->query($query); if (!$result) { @@ -42,12 +42,12 @@ if (!defined("DRIVER")) { $row = $result->fetch_array(); return $row[$field]; } - + function quote($string) { return "'" . $this->escape_string($string) . "'"; } } - + } elseif (extension_loaded("mysql") && !(ini_get("sql.safe_mode") && extension_loaded("pdo_mysql"))) { class Min_DB { var @@ -58,7 +58,7 @@ if (!defined("DRIVER")) { $error, ///< @var string last error message $_link, $_result ///< @access private ; - + /** Connect to server * @param string * @param string @@ -85,7 +85,7 @@ if (!defined("DRIVER")) { } return (bool) $this->_link; } - + /** Quote string to use in SQL * @param string * @return string escaped string enclosed in ' @@ -93,7 +93,7 @@ if (!defined("DRIVER")) { function quote($string) { return "'" . mysql_real_escape_string($string, $this->_link) . "'"; } - + /** Select database * @param string * @return bool @@ -101,7 +101,7 @@ if (!defined("DRIVER")) { function select_db($database) { return mysql_select_db($database, $this->_link); } - + /** Send query * @param string * @param bool @@ -122,7 +122,7 @@ if (!defined("DRIVER")) { } return new Min_Result($result); } - + /** Send query with more resultsets * @param string * @return bool @@ -130,14 +130,14 @@ if (!defined("DRIVER")) { function multi_query($query) { return $this->_result = $this->query($query); } - + /** Get current resultset * @return Min_Result */ function store_result() { return $this->_result; } - + /** Fetch next resultset * @return bool */ @@ -145,7 +145,7 @@ if (!defined("DRIVER")) { // MySQL extension doesn't support multiple results return false; } - + /** Get single field from result * @param string * @param int @@ -159,13 +159,13 @@ if (!defined("DRIVER")) { return mysql_result($result->_result, 0, $field); } } - + class Min_Result { var $num_rows, ///< @var int number of rows in the result $_result, $_offset = 0 ///< @access private ; - + /** Constructor * @param resource */ @@ -173,21 +173,21 @@ if (!defined("DRIVER")) { $this->_result = $result; $this->num_rows = mysql_num_rows($result); } - + /** Fetch next row as associative array * @return array */ function fetch_assoc() { return mysql_fetch_assoc($this->_result); } - + /** Fetch next row as numbered array * @return array */ function fetch_row() { return mysql_fetch_row($this->_result); } - + /** Fetch next field * @return object properties: name, type, orgtable, orgname, charsetnr */ @@ -198,45 +198,45 @@ if (!defined("DRIVER")) { $return->charsetnr = ($return->blob ? 63 : 0); return $return; } - + /** Free result set */ function __destruct() { mysql_free_result($this->_result); //! not called in PHP 4 which is a problem with mysql.trace_mode } } - + } elseif (extension_loaded("pdo_mysql")) { class Min_DB extends Min_PDO { var $extension = "PDO_MySQL"; - + function connect($server, $username, $password) { $this->dsn("mysql:host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\\d)~', ';port=\\1', $server)), $username, $password); $this->query("SET NAMES utf8"); // charset in DSN is ignored return true; } - + function select_db($database) { // database selection is separated from the connection so dbname in DSN can't be used return $this->query("USE " . idf_escape($database)); } - + function query($query, $unbuffered = false) { $this->setAttribute(1000, !$unbuffered); // 1000 - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY return parent::query($query, $unbuffered); } } - + } class Min_Driver extends Min_SQL { - + function insert($table, $set) { return ($set ? parent::insert($table, $set) : queries("INSERT INTO " . table($table) . " ()\nVALUES ()")); } - + function insertUpdate($table, $rows, $primary) { $columns = array_keys(reset($rows)); $prefix = "INSERT INTO " . table($table) . " (" . implode(", ", $columns) . ") VALUES\n"; @@ -261,7 +261,7 @@ if (!defined("DRIVER")) { } return queries($prefix . implode(",\n", $values) . $suffix); } - + } @@ -366,7 +366,7 @@ if (!defined("DRIVER")) { function engines() { $return = array(); foreach (get_rows("SHOW ENGINES") as $row) { - if (ereg("YES|DEFAULT", $row["Support"])) { + if (preg_match("~YES|DEFAULT~", $row["Support"])) { $return[] = $row["Engine"]; } } @@ -441,7 +441,7 @@ if (!defined("DRIVER")) { * @return bool */ function fk_support($table_status) { - return eregi("InnoDB|IBMDB2I", $table_status["Engine"]); + return preg_match('~InnoDB|IBMDB2I~i', $table_status["Engine"]); } /** Get information about fields @@ -458,10 +458,10 @@ if (!defined("DRIVER")) { "type" => $match[1], "length" => $match[2], "unsigned" => ltrim($match[3] . $match[4]), - "default" => ($row["Default"] != "" || ereg("char|set", $match[1]) ? $row["Default"] : null), + "default" => ($row["Default"] != "" || preg_match("~char|set~", $match[1]) ? $row["Default"] : null), "null" => ($row["Null"] == "YES"), "auto_increment" => ($row["Extra"] == "auto_increment"), - "on_update" => (eregi('^on update (.+)', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23 + "on_update" => (preg_match('~^on update (.+)~i', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23 "collation" => $row["Collation"], "privileges" => array_flip(explode(",", $row["Privileges"])), "comment" => $row["Comment"], @@ -565,7 +565,7 @@ if (!defined("DRIVER")) { */ function error_line() { global $connection; - if (ereg(' at line ([0-9]+)$', $connection->error, $regs)) { + if (preg_match('~ at line ([0-9]+)$~', $connection->error, $regs)) { return $regs[1] - 1; } } @@ -579,7 +579,7 @@ if (!defined("DRIVER")) { set_session("dbs", null); return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . q($collation) : "")); } - + /** Drop databases * @param array * @return bool @@ -589,7 +589,7 @@ if (!defined("DRIVER")) { set_session("dbs", null); return apply_queries("DROP DATABASE", $databases, 'idf_escape'); } - + /** Rename database from DB * @param string new name * @param string @@ -609,7 +609,7 @@ if (!defined("DRIVER")) { } return false; } - + /** Generate modifier for auto increment column * @return string */ @@ -629,7 +629,7 @@ if (!defined("DRIVER")) { } return " AUTO_INCREMENT$auto_increment_index"; } - + /** Run commands to create or alter table * @param string "" to create * @param string new name @@ -666,7 +666,7 @@ if (!defined("DRIVER")) { $alter[] = $status; return queries("ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter)); } - + /** Run commands to alter indexes * @param string escaped table name * @param array of array("index type", "name", "(columns definition)") or array("index type", "name", "DROP") @@ -681,7 +681,7 @@ if (!defined("DRIVER")) { } return queries("ALTER TABLE " . table($table) . implode(",", $alter)); } - + /** Run commands to truncate tables * @param array * @return bool @@ -689,7 +689,7 @@ if (!defined("DRIVER")) { function truncate_tables($tables) { return apply_queries("TRUNCATE TABLE", $tables); } - + /** Drop views * @param array * @return bool @@ -697,7 +697,7 @@ if (!defined("DRIVER")) { function drop_views($views) { return queries("DROP VIEW " . implode(", ", array_map('table', $views))); } - + /** Drop tables * @param array * @return bool @@ -705,7 +705,7 @@ if (!defined("DRIVER")) { function drop_tables($tables) { return queries("DROP TABLE " . implode(", ", array_map('table', $tables))); } - + /** Move tables to other schema * @param array * @param array @@ -720,7 +720,7 @@ if (!defined("DRIVER")) { return queries("RENAME TABLE " . implode(", ", $rename)); //! move triggers } - + /** Copy tables to other schema * @param array * @param array @@ -749,7 +749,7 @@ if (!defined("DRIVER")) { } return true; } - + /** Get information about trigger * @param string trigger name * @return array array("Trigger" => , "Timing" => , "Event" => , "Type" => , "Statement" => ) @@ -761,7 +761,7 @@ if (!defined("DRIVER")) { $rows = get_rows("SHOW TRIGGERS WHERE `Trigger` = " . q($name)); return reset($rows); } - + /** Get defined triggers * @param string * @return array array($name => array($timing, $event)) @@ -773,7 +773,7 @@ if (!defined("DRIVER")) { } return $return; } - + /** Get trigger options * @return array ("Timing" => array(), "Type" => array()) */ @@ -784,7 +784,7 @@ if (!defined("DRIVER")) { "Type" => array("FOR EACH ROW"), ); } - + /** Get information about stored routine * @param string * @param string "FUNCTION" or "PROCEDURE" @@ -822,21 +822,21 @@ if (!defined("DRIVER")) { "language" => "SQL", // available in information_schema.ROUTINES.PARAMETER_STYLE ); } - + /** Get list of routines * @return array ("ROUTINE_TYPE" => , "ROUTINE_NAME" => , "DTD_IDENTIFIER" => ) */ function routines() { return get_rows("SELECT ROUTINE_NAME, ROUTINE_TYPE, DTD_IDENTIFIER FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . q(DB)); } - + /** Get list of available routine languages * @return array */ function routine_languages() { return array(); // "SQL" not required } - + /** Get last auto increment ID * @return string */ @@ -844,7 +844,7 @@ if (!defined("DRIVER")) { global $connection; return $connection->result("SELECT LAST_INSERT_ID()"); // mysql_insert_id() truncates bigint } - + /** Explain select * @param Min_DB * @param string @@ -853,7 +853,7 @@ if (!defined("DRIVER")) { function explain($connection, $query) { return $connection->query("EXPLAIN " . ($connection->server_info >= 5.1 ? "PARTITIONS " : "") . $query); } - + /** Get approximate number of rows * @param array * @param array @@ -862,28 +862,28 @@ if (!defined("DRIVER")) { function found_rows($table_status, $where) { return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]); } - + /** Get user defined types * @return array */ function types() { return array(); } - + /** Get existing schemas * @return array */ function schemas() { return array(); } - + /** Get current schema * @return string */ function get_schema() { return ""; } - + /** Set current schema * @param string * @return bool @@ -891,7 +891,7 @@ if (!defined("DRIVER")) { function set_schema($schema) { return true; } - + /** Get SQL command to create table * @param string * @param bool @@ -905,7 +905,7 @@ if (!defined("DRIVER")) { } return $return; } - + /** Get SQL command to truncate table * @param string * @return string @@ -913,7 +913,7 @@ if (!defined("DRIVER")) { function truncate_sql($table) { return "TRUNCATE " . table($table); } - + /** Get SQL command to change database * @param string * @return string @@ -921,7 +921,7 @@ if (!defined("DRIVER")) { function use_sql($database) { return "USE " . idf_escape($database); } - + /** Get SQL commands to create triggers * @param string * @param string @@ -935,69 +935,69 @@ if (!defined("DRIVER")) { } return $return; } - + /** Get server variables * @return array ($name => $value) */ function show_variables() { return get_key_vals("SHOW VARIABLES"); } - + /** Get process list * @return array ($row) */ function process_list() { return get_rows("SHOW FULL PROCESSLIST"); } - + /** Get status variables * @return array ($name => $value) */ function show_status() { return get_key_vals("SHOW STATUS"); } - + /** Convert field in select and edit * @param array one element from fields() * @return string */ function convert_field($field) { - if (ereg("binary", $field["type"])) { + if (preg_match("~binary~", $field["type"])) { return "HEX(" . idf_escape($field["field"]) . ")"; } if ($field["type"] == "bit") { return "BIN(" . idf_escape($field["field"]) . " + 0)"; // + 0 is required outside MySQLnd } - if (ereg("geometry|point|linestring|polygon", $field["type"])) { + if (preg_match("~geometry|point|linestring|polygon~", $field["type"])) { return "AsWKT(" . idf_escape($field["field"]) . ")"; } } - + /** Convert value in edit after applying functions back * @param array one element from fields() * @param string * @return string */ function unconvert_field($field, $return) { - if (ereg("binary", $field["type"])) { + if (preg_match("~binary~", $field["type"])) { $return = "UNHEX($return)"; } if ($field["type"] == "bit") { $return = "CONV($return, 2, 10) + 0"; } - if (ereg("geometry|point|linestring|polygon", $field["type"])) { + if (preg_match("~geometry|point|linestring|polygon~", $field["type"])) { $return = "GeomFromText($return)"; } return $return; } - + /** Check whether a feature is supported * @param string "comment", "copy", "database", "drop_col", "dump", "event", "kill", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "table", "trigger", "type", "variables", "view" * @return bool */ function support($feature) { global $connection; - return !ereg("scheme|sequence|type" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : ""), $feature); + return !preg_match("~scheme|sequence|type" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : "") . "~", $feature); } $jush = "sql"; ///< @var string JUSH identifier diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index ebd388d6..e848c91c 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -12,10 +12,10 @@ if (isset($_GET["oracle"])) { if (ini_bool("html_errors")) { $error = html_entity_decode(strip_tags($error)); } - $error = ereg_replace('^[^:]*: ', '', $error); + $error = preg_replace('~^[^:]*: ~', '', $error); $this->error = $error; } - + function connect($server, $username, $password) { $this->_link = @oci_new_connect($username, $password, $server, "AL32UTF8"); if ($this->_link) { @@ -59,15 +59,15 @@ if (isset($_GET["oracle"])) { function multi_query($query) { return $this->_result = $this->query($query); } - + function store_result() { return $this->_result; } - + function next_result() { return false; } - + function result($query, $field = 1) { $result = $this->query($query); if (!is_object($result) || !oci_fetch($result->_result)) { @@ -92,7 +92,7 @@ if (isset($_GET["oracle"])) { } return $row; } - + function fetch_assoc() { return $this->_convert(oci_fetch_assoc($this->_result)); } @@ -107,41 +107,41 @@ if (isset($_GET["oracle"])) { $return->name = oci_field_name($this->_result, $column); $return->orgname = $return->name; $return->type = oci_field_type($this->_result, $column); - $return->charsetnr = (ereg("raw|blob|bfile", $return->type) ? 63 : 0); // 63 - binary + $return->charsetnr = (preg_match("~raw|blob|bfile~", $return->type) ? 63 : 0); // 63 - binary return $return; } - + function __destruct() { oci_free_statement($this->_result); } } - + } elseif (extension_loaded("pdo_oci")) { class Min_DB extends Min_PDO { var $extension = "PDO_OCI"; - + function connect($server, $username, $password) { $this->dsn("oci:dbname=//$server;charset=AL32UTF8", $username, $password); return true; } - + function select_db($database) { return true; } } - + } - + class Min_Driver extends Min_SQL { - + //! support empty $set in insert() - + function begin() { return true; // automatic start } - + } @@ -203,7 +203,7 @@ ORDER BY 1" function count_tables($databases) { return array(); } - + function table_status($name = "") { $return = array(); $search = q($name); @@ -222,7 +222,7 @@ ORDER BY 1" function is_view($table_status) { return $table_status["Engine"] == "view"; } - + function fk_support($table_status) { return true; } @@ -272,7 +272,7 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) { $rows = get_rows('SELECT text "select" FROM user_views WHERE view_name = ' . q($name)); return reset($rows); } - + function collations() { return array(); //! } @@ -285,15 +285,15 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) { global $connection; return h($connection->error); //! highlight sqltext from offset } - + function explain($connection, $query) { $connection->query("EXPLAIN PLAN FOR $query"); return $connection->query("SELECT * FROM plan_table"); } - + function found_rows($table_status, $where) { } - + function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { $alter = $drop = array(); foreach ($fields as $field) { @@ -315,11 +315,11 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) { && ($table == $name || queries("ALTER TABLE " . table($table) . " RENAME TO " . table($name))) ; } - + function foreign_keys($table) { return array(); //! } - + function truncate_tables($tables) { return apply_queries("TRUNCATE TABLE", $tables); } @@ -335,25 +335,25 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) { function last_id() { return 0; //! } - + function schemas() { return get_vals("SELECT DISTINCT owner FROM dba_segments WHERE owner IN (SELECT username FROM dba_users WHERE default_tablespace NOT IN ('SYSTEM','SYSAUX'))"); } - + function get_schema() { global $connection; return $connection->result("SELECT sys_context('USERENV', 'SESSION_USER') FROM dual"); } - + function set_schema($scheme) { global $connection; return $connection->query("ALTER SESSION SET CURRENT_SCHEMA = " . idf_escape($scheme)); } - + function show_variables() { return get_key_vals('SELECT name, display_value FROM v$parameter'); } - + function process_list() { return get_rows('SELECT sess.process AS "process", sess.username AS "user", sess.schemaname AS "schema", sess.status AS "status", sess.wait_class AS "wait_class", sess.seconds_in_wait AS "seconds_in_wait", sql.sql_text AS "sql_text", sess.machine AS "machine", sess.port AS "port" FROM v$session sess LEFT OUTER JOIN v$sql sql @@ -362,23 +362,23 @@ WHERE sess.type = \'USER\' ORDER BY PROCESS '); } - + function show_status() { $rows = get_rows('SELECT * FROM v$instance'); return reset($rows); } - + function convert_field($field) { } - + function unconvert_field($field, $return) { return $return; } - + function support($feature) { - return ereg('^(database|table|sql|indexes|view|scheme|processlist|drop_col|variables|status)$', $feature); //! + return preg_match('~^(database|table|sql|indexes|view|scheme|processlist|drop_col|variables|status)$~', $feature); //! } - + $jush = "oracle"; $types = array(); $structured_types = array(); diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index bc0dbef9..0240b6be 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -7,15 +7,15 @@ if (isset($_GET["pgsql"])) { if (extension_loaded("pgsql")) { class Min_DB { var $extension = "PgSQL", $_link, $_result, $_string, $_database = true, $server_info, $affected_rows, $error; - + function _error($errno, $error) { if (ini_bool("html_errors")) { $error = html_entity_decode(strip_tags($error)); } - $error = ereg_replace('^[^:]*: ', '', $error); + $error = preg_replace('~^[^:]*: ~', '', $error); $this->error = $error; } - + function connect($server, $username, $password) { global $adminer; $db = $adminer->database(); @@ -35,11 +35,11 @@ if (isset($_GET["pgsql"])) { } return (bool) $this->_link; } - + function quote($string) { return "'" . pg_escape_string($this->_link, $string) . "'"; //! bytea } - + function select_db($database) { global $adminer; if ($database == $adminer->database()) { @@ -51,11 +51,11 @@ if (isset($_GET["pgsql"])) { } return $return; } - + function close() { $this->_link = @pg_connect("$this->_string dbname='postgres'"); } - + function query($query, $unbuffered = false) { $result = @pg_query($this->_link, $query); $this->error = ""; @@ -68,20 +68,20 @@ if (isset($_GET["pgsql"])) { } return new Min_Result($result); } - + function multi_query($query) { return $this->_result = $this->query($query); } - + function store_result() { return $this->_result; } - + function next_result() { // PgSQL extension doesn't support multiple results return false; } - + function result($query, $field = 0) { $result = $this->query($query); if (!$result || !$result->num_rows) { @@ -90,23 +90,23 @@ if (isset($_GET["pgsql"])) { return pg_fetch_result($result->_result, 0, $field); } } - + class Min_Result { var $_result, $_offset = 0, $num_rows; - + function Min_Result($result) { $this->_result = $result; $this->num_rows = pg_num_rows($result); } - + function fetch_assoc() { return pg_fetch_assoc($this->_result); } - + function fetch_row() { return pg_fetch_row($this->_result); } - + function fetch_field() { $column = $this->_offset++; $return = new stdClass; @@ -119,16 +119,16 @@ if (isset($_GET["pgsql"])) { $return->charsetnr = ($return->type == "bytea" ? 63 : 0); // 63 - binary return $return; } - + function __destruct() { pg_free_result($this->_result); } } - + } elseif (extension_loaded("pdo_pgsql")) { class Min_DB extends Min_PDO { var $extension = "PDO_PgSQL"; - + function connect($server, $username, $password) { global $adminer; $db = $adminer->database(); @@ -137,22 +137,22 @@ if (isset($_GET["pgsql"])) { //! connect without DB in case of an error return true; } - + function select_db($database) { global $adminer; return ($adminer->database() == $database); } - + function close() { } } - + } class Min_Driver extends Min_SQL { - + function insertUpdate($table, $rows, $primary) { global $connection; foreach ($rows as $set) { @@ -172,7 +172,7 @@ if (isset($_GET["pgsql"])) { } return true; } - + } @@ -197,11 +197,11 @@ if (isset($_GET["pgsql"])) { } return $connection->error; } - + function get_databases() { return get_vals("SELECT datname FROM pg_database ORDER BY datname"); } - + function limit($query, $where, $limit, $offset = 0, $separator = " ") { return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } @@ -209,7 +209,7 @@ if (isset($_GET["pgsql"])) { function limit1($query, $where) { return " $query$where"; } - + function db_collation($db, $collations) { global $connection; return $connection->result("SHOW LC_COLLATE"); //! respect $db @@ -218,16 +218,16 @@ if (isset($_GET["pgsql"])) { function engines() { return array(); } - + function logged_user() { global $connection; return $connection->result("SELECT user"); } - + function tables_list() { return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema() ORDER BY table_name"); } - + function count_tables($databases) { return array(); // would require reconnect } @@ -244,15 +244,15 @@ AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema( } return ($name != "" ? $return[$name] : $return); } - + function is_view($table_status) { return $table_status["Engine"] == "view"; } - + function fk_support($table_status) { return true; } - + function fields($table) { $return = array(); $aliases = array( @@ -272,13 +272,13 @@ ORDER BY a.attnum" ) as $row) { //! collation, primary $type = $row["full_type"]; - if (ereg('(.+)\\((.*)\\)$', $row["full_type"], $match)) { + if (preg_match('~(.+)\\((.*)\\)$~', $row["full_type"], $match)) { list(, $type, $row["length"]) = $match; } $row["type"] = ($aliases[$type] ? $aliases[$type] : $type); $row["full_type"] = $row["type"] . ($row["length"] ? "($row[length])" : ""); $row["null"] = !$row["attnotnull"]; - $row["auto_increment"] = eregi("^nextval\\(", $row["default"]); + $row["auto_increment"] = preg_match('~^nextval\\(~i', $row["default"]); $row["privileges"] = array("insert" => 1, "select" => 1, "update" => 1); if (preg_match('~(.+)::[^)]+(.*)~', $row["default"], $match)) { $row["default"] = ($match[1][0] == "'" ? idf_unescape($match[1]) : $match[1]) . $match[2]; @@ -287,7 +287,7 @@ ORDER BY a.attnum" } return $return; } - + function indexes($table, $connection2 = null) { global $connection; if (!is_object($connection2)) { @@ -311,7 +311,7 @@ ORDER BY a.attnum" } return $return; } - + function foreign_keys($table) { global $on_actions; $return = array(); @@ -335,21 +335,21 @@ ORDER BY conkey, conname") as $row) { } return $return; } - + function view($name) { global $connection; return array("select" => $connection->result("SELECT pg_get_viewdef(" . q($name) . ")")); } - + function collations() { //! supported in CREATE DATABASE return array(); } - + function information_schema($db) { return ($db == "information_schema"); } - + function error() { global $connection; $return = h($connection->error); @@ -358,26 +358,26 @@ ORDER BY conkey, conname") as $row) { } return nl_br($return); } - + function create_database($db, $collation) { return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " ENCODING " . idf_escape($collation) : "")); } - + function drop_databases($databases) { global $connection; $connection->close(); return apply_queries("DROP DATABASE", $databases, 'idf_escape'); } - + function rename_database($name, $collation) { //! current database cannot be renamed return queries("ALTER DATABASE " . idf_escape(DB) . " RENAME TO " . idf_escape($name)); } - + function auto_increment() { return ""; } - + function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { $alter = array(); $queries = array(); @@ -431,7 +431,7 @@ ORDER BY conkey, conname") as $row) { } return true; } - + function alter_indexes($table, $alter) { $create = array(); $drop = array(); @@ -462,20 +462,20 @@ ORDER BY conkey, conname") as $row) { } return true; } - + function truncate_tables($tables) { return queries("TRUNCATE " . implode(", ", array_map('table', $tables))); return true; } - + function drop_views($views) { return queries("DROP VIEW " . implode(", ", array_map('table', $views))); } - + function drop_tables($tables) { return queries("DROP TABLE " . implode(", ", array_map('table', $tables))); } - + function move_tables($tables, $views, $target) { foreach ($tables as $table) { if (!queries("ALTER TABLE " . table($table) . " SET SCHEMA " . idf_escape($target))) { @@ -489,7 +489,7 @@ ORDER BY conkey, conname") as $row) { } return true; } - + function trigger($name) { if ($name == "") { return array("Statement" => "EXECUTE PROCEDURE ()"); @@ -497,7 +497,7 @@ ORDER BY conkey, conname") as $row) { $rows = get_rows('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", \'FOR EACH \' || action_orientation AS "Type", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . q($_GET["trigger"]) . ' AND trigger_name = ' . q($name)); return reset($rows); } - + function triggers($table) { $return = array(); foreach (get_rows("SELECT * FROM information_schema.triggers WHERE event_object_table = " . q($table)) as $row) { @@ -505,14 +505,14 @@ ORDER BY conkey, conname") as $row) { } return $return; } - + function trigger_options() { return array( "Timing" => array("BEFORE", "AFTER"), "Type" => array("FOR EACH ROW", "FOR EACH STATEMENT"), ); } - + /* function routine($name, $type) { //! there can be more functions with the same name differing only in parameters, it must be also passed to DROP FUNCTION @@ -526,7 +526,7 @@ WHERE n.nspname = current_schema() AND p.proname = ' . q($name)); return $rows[0]; } */ - + function routines() { return get_rows('SELECT p.proname AS "ROUTINE_NAME", p.proargtypes AS "ROUTINE_TYPE", pg_catalog.format_type(p.prorettype, NULL) AS "DTD_IDENTIFIER" FROM pg_catalog.pg_namespace n @@ -534,23 +534,23 @@ JOIN pg_catalog.pg_proc p ON p.pronamespace = n.oid WHERE n.nspname = current_schema() ORDER BY p.proname'); } - + function routine_languages() { return get_vals("SELECT langname FROM pg_catalog.pg_language"); } - + function last_id() { return 0; // there can be several sequences } - + function explain($connection, $query) { return $connection->query("EXPLAIN $query"); } - + function found_rows($table_status, $where) { global $connection; - if (ereg( - " rows=([0-9]+)", + if (preg_match( + "~ rows=([0-9]+)~", $connection->result("EXPLAIN SELECT * FROM " . idf_escape($table_status["Name"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")), $regs )) { @@ -558,7 +558,7 @@ ORDER BY p.proname'); } return false; } - + function types() { return get_vals("SELECT typname FROM pg_type @@ -567,16 +567,16 @@ AND typtype IN ('b','d','e') AND typelem = 0" ); } - + function schemas() { return get_vals("SELECT nspname FROM pg_namespace ORDER BY nspname"); } - + function get_schema() { global $connection; return $connection->result("SELECT current_schema()"); } - + function set_schema($schema) { global $connection, $types, $structured_types; $return = $connection->query("SET search_path TO " . idf_escape($schema)); @@ -588,11 +588,11 @@ AND typelem = 0" } return $return; } - + function use_sql($database) { return "\connect " . idf_escape($database); } - + function show_variables() { return get_key_vals("SHOW ALL"); } @@ -601,21 +601,21 @@ AND typelem = 0" global $connection; return get_rows("SELECT * FROM pg_stat_activity ORDER BY " . ($connection->server_info < 9.2 ? "procpid" : "pid")); } - + function show_status() { } - + function convert_field($field) { } - + function unconvert_field($field, $return) { return $return; } - + function support($feature) { - return ereg('^(database|table|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine| + return preg_match('~^(database|table|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine| } - + $jush = "pgsql"; $types = array(); $structured_types = array(); diff --git a/adminer/drivers/simpledb.inc.php b/adminer/drivers/simpledb.inc.php index 08f08464..2b81afac 100644 --- a/adminer/drivers/simpledb.inc.php +++ b/adminer/drivers/simpledb.inc.php @@ -12,15 +12,15 @@ $drivers["simpledb"] = "SimpleDB"; if (isset($_GET["simpledb"])) { $possible_drivers = array("SimpleXML"); define("DRIVER", "simpledb"); - + if (class_exists('SimpleXMLElement')) { class Min_DB { var $extension = "SimpleXML", $server_info = '2009-04-15', $error, $timeout, $next, $affected_rows, $_result; - + function select_db($database) { return ($database == "domain"); } - + function query($query, $unbuffered = false) { $params = array('SelectExpression' => $query, 'ConsistentRead' => 'true'); if ($this->next) { @@ -42,28 +42,28 @@ if (isset($_GET["simpledb"])) { } return new Min_Result($result); } - + function multi_query($query) { return $this->_result = $this->query($query); } - + function store_result() { return $this->_result; } - + function next_result() { return false; } - + function quote($string) { return "'" . str_replace("'", "''", $string) . "'"; } - + } - + class Min_Result { var $num_rows, $_rows = array(), $_offset = 0; - + function Min_Result($result) { foreach ($result as $item) { $row = array(); @@ -83,11 +83,11 @@ if (isset($_GET["simpledb"])) { } $this->num_rows = count($this->_rows); } - + function _processValue($element) { return (is_object($element) && $element['encoding'] == 'base64' ? base64_decode($element) : (string) $element); } - + function fetch_assoc() { $row = current($this->_rows); if (!$row) { @@ -100,7 +100,7 @@ if (isset($_GET["simpledb"])) { next($this->_rows); return $return; } - + function fetch_row() { $return = $this->fetch_assoc(); if (!$return) { @@ -108,19 +108,19 @@ if (isset($_GET["simpledb"])) { } return array_values($return); } - + function fetch_field() { $keys = array_keys($this->_rows[0]); return (object) array('name' => $keys[$this->_offset++]); } - + } } - - - + + + class Min_Driver extends Min_SQL { - + function _chunkRequest($ids, $action, $params, $expand = array()) { global $connection; foreach (array_chunk($ids, 25) as $chunk) { @@ -138,7 +138,7 @@ if (isset($_GET["simpledb"])) { $connection->affected_rows = count($ids); return true; } - + function _extractIds($table, $queryWhere, $limit) { $return = array(); if (preg_match_all("~itemName\(\) = ('[^']*+')+~", $queryWhere, $matches)) { @@ -150,7 +150,7 @@ if (isset($_GET["simpledb"])) { } return $return; } - + function select($table, $select, $where, $group, $order, $limit, $page) { global $connection; $connection->next = $_GET["next"]; @@ -158,7 +158,7 @@ if (isset($_GET["simpledb"])) { $connection->next = 0; return $return; } - + function delete($table, $queryWhere, $limit = 0) { return $this->_chunkRequest( $this->_extractIds($table, $queryWhere, $limit), @@ -166,7 +166,7 @@ if (isset($_GET["simpledb"])) { array('DomainName' => $table) ); } - + function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") { $delete = array(); $insert = array(); @@ -188,7 +188,7 @@ if (isset($_GET["simpledb"])) { && (!$delete || $this->_chunkRequest($ids, 'BatchDeleteAttributes', $params, $delete)) ; } - + function insert($table, $set) { $params = array("DomainName" => $table); $i = 0; @@ -207,7 +207,7 @@ if (isset($_GET["simpledb"])) { } return sdb_request('PutAttributes', $params); } - + function insertUpdate($table, $rows, $primary) { //! use one batch request foreach ($rows as $set) { @@ -217,48 +217,48 @@ if (isset($_GET["simpledb"])) { } return true; } - + function begin() { return false; } - + function commit() { return false; } - + function rollback() { return false; } - + } - - - + + + function connect() { return new Min_DB; } - + function support($feature) { - return ereg('sql', $feature); + return preg_match('~sql~', $feature); } - + function logged_user() { global $adminer; $credentials = $adminer->credentials(); return $credentials[1]; } - + function get_databases() { return array("domain"); } - + function collations() { return array(); } - + function db_collation($db, $collations) { } - + function tables_list() { global $connection; $return = array(); @@ -270,7 +270,7 @@ if (isset($_GET["simpledb"])) { } return $return; } - + function table_status($name = "", $fast = false) { $return = array(); foreach (($name != "" ? array($name => true) : tables_list()) as $table => $type) { @@ -295,27 +295,27 @@ if (isset($_GET["simpledb"])) { } return $return; } - + function explain($connection, $query) { } - + function error() { global $connection; return h($connection->error); } - + function information_schema() { } - + function is_view($table_status) { } - + function indexes($table, $connection2 = null) { return array( array("type" => "PRIMARY", "columns" => array("itemName()")), ); } - + function fields($table) { $return = array(); foreach ((array) $_POST["field_keys"] as $key => $val) { @@ -332,38 +332,38 @@ if (isset($_GET["simpledb"])) { } return $return; } - + function foreign_keys($table) { return array(); } - + function table($idf) { return idf_escape($idf); } - + function idf_escape($idf) { return "`" . str_replace("`", "``", $idf) . "`"; } - + function limit($query, $where, $limit, $offset = 0, $separator = " ") { return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" : ""); } - + function unconvert_field($field, $return) { return $return; } - + function fk_support($table_status) { } - + function engines() { return array(); } - + function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { return ($table == "" && sdb_request('CreateDomain', array('DomainName' => $name))); } - + function drop_tables($tables) { foreach ($tables as $table) { if (!sdb_request('DeleteDomain', array('DomainName' => $table))) { @@ -372,20 +372,20 @@ if (isset($_GET["simpledb"])) { } return true; } - + function count_tables($databases) { foreach ($databases as $db) { return array($db => count(tables_list())); } } - + function found_rows($table_status, $where) { return ($where ? null : $table_status["Rows"]); } - + function last_id() { } - + function hmac($algo, $data, $key, $raw_output = false) { // can use hash_hmac() since PHP 5.1.2 $blocksize = 64; @@ -416,9 +416,9 @@ if (isset($_GET["simpledb"])) { $query .= '&' . rawurlencode($key) . '=' . rawurlencode($val); } $query = str_replace('%7E', '~', substr($query, 1)); - $query .= "&Signature=" . urlencode(base64_encode(hmac('sha1', "POST\n" . ereg_replace('^https?://', '', $host) . "\n/\n$query", $secret, true))); + $query .= "&Signature=" . urlencode(base64_encode(hmac('sha1', "POST\n" . preg_replace('~^https?://~', '', $host) . "\n/\n$query", $secret, true))); @ini_set('track_errors', 1); // @ - may be disabled - $file = @file_get_contents((ereg('^https?://', $host) ? $host : "http://$host"), false, stream_context_create(array('http' => array( + $file = @file_get_contents((preg_match('~^https?://~', $host) ? $host : "http://$host"), false, stream_context_create(array('http' => array( 'method' => 'POST', // may not fit in URL with GET 'content' => $query, 'ignore_errors' => 1, // available since PHP 5.2.10 @@ -443,7 +443,7 @@ if (isset($_GET["simpledb"])) { $tag = $action . "Result"; return ($xml->$tag ? $xml->$tag : true); } - + function sdb_request_all($action, $tag, $params = array(), $timeout = 0) { $return = array(); $start = ($timeout ? microtime(true) : 0); @@ -470,7 +470,7 @@ if (isset($_GET["simpledb"])) { } while ($xml->NextToken); return $return; } - + $jush = "simpledb"; $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL"); $functions = array(); diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index dd7b9989..6fd76726 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -7,16 +7,16 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { define("DRIVER", (isset($_GET["sqlite"]) ? "sqlite" : "sqlite2")); if (class_exists(isset($_GET["sqlite"]) ? "SQLite3" : "SQLiteDatabase")) { if (isset($_GET["sqlite"])) { - + class Min_SQLite { var $extension = "SQLite3", $server_info, $affected_rows, $errno, $error, $_link; - + function Min_SQLite($filename) { $this->_link = new SQLite3($filename); $version = $this->_link->version(); $this->server_info = $version["versionString"]; } - + function query($query) { $result = @$this->_link->query($query); $this->error = ""; @@ -30,18 +30,18 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { $this->affected_rows = $this->_link->changes(); return true; } - + function quote($string) { return (is_utf8($string) ? "'" . $this->_link->escapeString($string) . "'" : "x'" . reset(unpack('H*', $string)) . "'" ); } - + function store_result() { return $this->_result; } - + function result($query, $field = 0) { $result = $this->query($query); if (!is_object($result)) { @@ -51,22 +51,22 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return $row[$field]; } } - + class Min_Result { var $_result, $_offset = 0, $num_rows; - + function Min_Result($result) { $this->_result = $result; } - + function fetch_assoc() { return $this->_result->fetchArray(SQLITE3_ASSOC); } - + function fetch_row() { return $this->_result->fetchArray(SQLITE3_NUM); } - + function fetch_field() { $column = $this->_offset++; $type = $this->_result->columnType($column); @@ -76,22 +76,22 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { "charsetnr" => ($type == SQLITE3_BLOB ? 63 : 0), // 63 - binary ); } - + function __desctruct() { return $this->_result->finalize(); } } - + } else { - + class Min_SQLite { var $extension = "SQLite", $server_info, $affected_rows, $error, $_link; - + function Min_SQLite($filename) { $this->server_info = sqlite_libversion(); $this->_link = new SQLiteDatabase($filename); } - + function query($query, $unbuffered = false) { $method = ($unbuffered ? "unbufferedQuery" : "query"); $result = @$this->_link->$method($query, SQLITE_BOTH, $error); @@ -105,15 +105,15 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return new Min_Result($result); } - + function quote($string) { return "'" . sqlite_escape_string($string) . "'"; } - + function store_result() { return $this->_result; } - + function result($query, $field = 0) { $result = $this->query($query); if (!is_object($result)) { @@ -123,17 +123,17 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return $row[$field]; } } - + class Min_Result { var $_result, $_offset = 0, $num_rows; - + function Min_Result($result) { $this->_result = $result; if (method_exists($result, 'numRows')) { // not available in unbuffered query $this->num_rows = $result->numRows(); } } - + function fetch_assoc() { $row = $this->_result->fetch(SQLITE_ASSOC); if (!$row) { @@ -145,11 +145,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return $return; } - + function fetch_row() { return $this->_result->fetch(SQLITE_NUM); } - + function fetch_field() { $name = $this->_result->fieldName($this->_offset++); $pattern = '(\\[.*]|"(?:[^"]|"")*"|(.+))'; @@ -163,41 +163,41 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { "orgtable" => $table, ); } - + } - + } - + } elseif (extension_loaded("pdo_sqlite")) { class Min_SQLite extends Min_PDO { var $extension = "PDO_SQLite"; - + function Min_SQLite($filename) { $this->dsn(DRIVER . ":$filename", "", ""); } } - + } if (class_exists("Min_SQLite")) { class Min_DB extends Min_SQLite { - + function Min_DB() { $this->Min_SQLite(":memory:"); } - + function select_db($filename) { - if (is_readable($filename) && $this->query("ATTACH " . $this->quote(ereg("(^[/\\\\]|:)", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { // is_readable - SQLite 3 + if (is_readable($filename) && $this->query("ATTACH " . $this->quote(preg_match("~(^[/\\\\]|:)~", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { // is_readable - SQLite 3 $this->Min_SQLite($filename); return true; } return false; } - + function multi_query($query) { return $this->_result = $this->query($query); } - + function next_result() { return false; } @@ -207,7 +207,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { class Min_Driver extends Min_SQL { - + function insertUpdate($table, $rows, $primary) { $values = array(); foreach ($rows as $set) { @@ -215,7 +215,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return queries("REPLACE INTO " . table($table) . " (" . implode(", ", array_keys(reset($rows))) . ") VALUES\n" . implode(",\n", $values)); } - + } @@ -284,7 +284,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { function is_view($table_status) { return $table_status["Engine"] == "view"; } - + function fk_support($table_status) { global $connection; return !$connection->result("SELECT sqlite_compileoption_used('OMIT_FOREIGN_KEY')"); @@ -297,11 +297,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { $default = $row["dflt_value"]; $return[$row["name"]] = array( "field" => $row["name"], - "type" => (eregi("int", $type) ? "integer" : (eregi("char|clob|text", $type) ? "text" : (eregi("blob", $type) ? "blob" : (eregi("real|floa|doub", $type) ? "real" : "numeric")))), + "type" => (preg_match('~int~i', $type) ? "integer" : (preg_match('~char|clob|text~i', $type) ? "text" : (preg_match('~blob~i', $type) ? "blob" : (preg_match('~real|floa|doub~i', $type) ? "real" : "numeric")))), "full_type" => $type, - "default" => (ereg("'(.*)'", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)), + "default" => (preg_match("~'(.*)'~", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)), "null" => !$row["notnull"], - "auto_increment" => eregi('^integer$', $type) && $row["pk"], //! possible false positive + "auto_increment" => preg_match('~^integer$~i', $type) && $row["pk"], //! possible false positive "privileges" => array("select" => 1, "insert" => 1, "update" => 1), "primary" => $row["pk"], ); @@ -323,14 +323,14 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { $sqls = get_key_vals("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = " . q($table)); foreach (get_rows("PRAGMA index_list(" . table($table) . ")") as $row) { $name = $row["name"]; - if (!ereg("^sqlite_", $name)) { + if (!preg_match("~^sqlite_~", $name)) { $return[$name]["type"] = ($row["unique"] ? "UNIQUE" : "INDEX"); $return[$name]["lengths"] = array(); foreach (get_rows("PRAGMA index_info(" . idf_escape($name) . ")") as $row1) { $return[$name]["columns"][] = $row1["name"]; } $return[$name]["descs"] = array(); - if (eregi('^CREATE( UNIQUE)? INDEX ' . quotemeta(idf_escape($name) . ' ON ' . idf_escape($table)) . ' \((.*)\)$', $sqls[$name], $regs)) { + if (preg_match('~^CREATE( UNIQUE)? INDEX ' . preg_quote(idf_escape($name) . ' ON ' . idf_escape($table), '~') . ' \((.*)\)$~i', $sqls[$name], $regs)) { preg_match_all('/("[^"]*+")+( DESC)?/', $regs[2], $matches); foreach ($matches[2] as $val) { $return[$name]["descs"][] = ($val ? '1' : null); @@ -372,7 +372,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { global $connection; return h($connection->error); } - + function check_sqlite_name($name) { // avoid creating PHP files on unsecured servers global $connection; @@ -383,7 +383,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return true; } - + function create_database($db, $collation) { global $connection; if (file_exists($db)) { @@ -399,7 +399,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { $link->query('DROP TABLE adminer'); return true; } - + function drop_databases($databases) { global $connection; $connection->Min_SQLite(":memory:"); // to unlock file, doesn't work in PDO on Windows @@ -411,7 +411,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return true; } - + function rename_database($name, $collation) { global $connection; if (!check_sqlite_name($name)) { @@ -421,11 +421,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { $connection->error = lang('File exists.'); return @rename(DB, $name); } - + function auto_increment() { return " PRIMARY KEY" . (DRIVER == "sqlite" ? " AUTOINCREMENT" : ""); } - + function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { $use_all_fields = ($table == "" || $foreign); foreach ($fields as $field) { @@ -525,7 +525,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return true; } - + function index_sql($table, $type, $name, $columns) { return "CREATE $type " . ($type != "INDEX" ? "INDEX " : "") . idf_escape($name != "" ? $name : uniqid($table . "_")) @@ -533,7 +533,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { . " $columns" ; } - + function alter_indexes($table, $alter) { foreach (array_reverse($alter) as $val) { if (!queries($val[2] == "DROP" @@ -545,23 +545,23 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return true; } - + function truncate_tables($tables) { return apply_queries("DELETE FROM", $tables); } - + function drop_views($views) { return apply_queries("DROP VIEW", $views); } - + function drop_tables($tables) { return apply_queries("DROP TABLE", $tables); } - + function move_tables($tables, $views, $target) { return false; } - + function trigger($name) { global $connection; if ($name == "") { @@ -570,7 +570,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { preg_match('~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*([a-z]+)\\s+([a-z]+)\\s+ON\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*(?:FOR\\s*EACH\\s*ROW\\s)?(.*)~is', $connection->result("SELECT sql FROM sqlite_master WHERE name = " . q($name)), $match); return array("Timing" => strtoupper($match[1]), "Event" => strtoupper($match[2]), "Trigger" => $name, "Statement" => $match[3]); } - + function triggers($table) { $return = array(); foreach (get_rows("SELECT * FROM sqlite_master WHERE type = 'trigger' AND tbl_name = " . q($table)) as $row) { @@ -579,58 +579,58 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return $return; } - + function trigger_options() { return array( "Timing" => array("BEFORE", "AFTER", "INSTEAD OF"), "Type" => array("FOR EACH ROW"), ); } - + function routine($name, $type) { // not supported by SQLite } - + function routines() { // not supported by SQLite } - + function routine_languages() { // not supported by SQLite } - + function begin() { return queries("BEGIN"); } - + function last_id() { global $connection; return $connection->result("SELECT LAST_INSERT_ROWID()"); } - + function explain($connection, $query) { return $connection->query("EXPLAIN $query"); } - + function found_rows($table_status, $where) { } - + function types() { return array(); } - + function schemas() { return array(); } - + function get_schema() { return ""; } - + function set_schema($scheme) { return true; } - + function create_sql($table, $auto_increment) { global $connection; $return = $connection->result("SELECT sql FROM sqlite_master WHERE type IN ('table', 'view') AND name = " . q($table)); @@ -642,18 +642,18 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return $return; } - + function truncate_sql($table) { return "DELETE FROM " . table($table); } - + function use_sql($database) { } - + function trigger_sql($table, $style) { return implode(get_vals("SELECT sql || ';;\n' FROM sqlite_master WHERE type = 'trigger' AND tbl_name = " . q($table))); } - + function show_variables() { global $connection; $return = array(); @@ -662,7 +662,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return $return; } - + function show_status() { $return = array(); foreach (get_vals("PRAGMA compile_options") as $option) { @@ -671,18 +671,18 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } return $return; } - + function convert_field($field) { } - + function unconvert_field($field, $return) { return $return; } - + function support($feature) { - return ereg('^(database|table|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$', $feature); + return preg_match('~^(database|table|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$~', $feature); } - + $jush = "sqlite"; $types = array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0); $structured_types = array_keys($types); diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index c5c3f47c..6e429009 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -11,8 +11,8 @@ if ($_POST && !$error) { $ext = dump_headers( (count($tables) == 1 ? key($tables) : DB), (DB == "" || count($tables) > 1)); - $is_sql = ereg('sql', $_POST["format"]); - + $is_sql = preg_match('~sql~', $_POST["format"]); + if ($is_sql) { echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump @@ -23,7 +23,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; " : "") . " "); } - + $style = $_POST["db_style"]; $databases = array(DB); if (DB == "") { @@ -32,11 +32,11 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; $databases = explode("\n", rtrim(str_replace("\r", "", $databases), "\n")); } } - + foreach ((array) $databases as $db) { $adminer->dumpDatabase($db); if ($connection->select_db($db)) { - if ($is_sql && ereg('CREATE', $style) && ($create = $connection->result("SHOW CREATE DATABASE " . idf_escape($db), 1))) { + if ($is_sql && preg_match('~CREATE~', $style) && ($create = $connection->result("SHOW CREATE DATABASE " . idf_escape($db), 1))) { if ($style == "DROP+CREATE") { echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n"; } @@ -47,7 +47,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; echo use_sql($db) . ";\n\n"; } $out = ""; - + if ($_POST["routines"]) { foreach (array("FUNCTION", "PROCEDURE") as $routine) { foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) { @@ -56,19 +56,19 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; } } } - + if ($_POST["events"]) { foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) { $out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . remove_definer($connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3)) . ";;\n\n"; } } - + if ($out) { echo "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n"; } } - + if ($_POST["table_style"] || $_POST["data_style"]) { $views = array(); foreach (table_status('', true) as $name => $table_status) { @@ -79,7 +79,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; $tmp_file = new TmpFile; ob_start(array($tmp_file, 'write'), 1e5); } - + $adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0)); if (is_view($table_status)) { $views[] = $name; @@ -90,7 +90,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) { echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n"; } - + if ($ext == "tar") { ob_end_flush(); tar_file((DB != "" ? "" : "$db/") . "$name.csv", $tmp_file); @@ -99,18 +99,18 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; } } } - + foreach ($views as $view) { $adminer->dumpTable($view, $_POST["table_style"], 1); } - + if ($ext == "tar") { echo pack("x512"); } } } } - + if ($is_sql) { echo "-- " . $connection->result("SELECT NOW()") . "\n"; } @@ -167,14 +167,14 @@ if (DB != "") { echo "
" . lang('You have no privileges to update this table.') . "\n"; } else { echo "
" . $adminer->fieldName($field); $default = $_GET["set"][bracket_escape($name)]; if ($default === null) { $default = $field["default"]; - if ($field["type"] == "bit" && ereg("^b'([01]*)'\$", $default, $regs)) { + if ($field["type"] == "bit" && preg_match("~^b'([01]*)'\$~", $default, $regs)) { $default = $regs[1]; } } $value = ($row !== null - ? ($row[$name] != "" && $jush == "sql" && ereg("enum|set", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name]) + ? ($row[$name] != "" && $jush == "sql" && preg_match("~enum|set~", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name]) : (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $default)) ); if (!$_POST["save"] && is_string($value)) { $value = $adminer->editVal($value, $field); } $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : ($value !== null ? '' : 'NULL')))); - if (ereg("time", $field["type"]) && $value == "CURRENT_TIMESTAMP") { + if (preg_match("~time~", $field["type"]) && $value == "CURRENT_TIMESTAMP") { $value = ""; $function = "now"; } input($field, $value, $function); echo "\n"; } - + if (!support("table")) { echo " | ||
---|---|---|
"; } - + echo " |
$val
" : $val));
- if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) {
+ $return = ($val === null ? "NULL" : (preg_match("~char|binary~", $field["type"]) && !preg_match("~var~", $field["type"]) ? "$val
" : $val));
+ if (preg_match('~blob|bytea|raw|file~', $field["type"]) && !is_utf8($val)) {
$return = lang('%d byte(s)', strlen(html_entity_decode($val, ENT_QUOTES)));
}
return ($link ? "$return" : $return);
@@ -401,14 +401,14 @@ username.form['auth[driver]'].onchange();
foreach ((array) $_GET["where"] as $val) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
$cond = " $val[op]";
- if (ereg('IN$', $val["op"])) {
+ if (preg_match('~IN$~', $val["op"])) {
$in = process_length($val["val"]);
$cond .= " (" . ($in != "" ? $in : "NULL") . ")";
} elseif ($val["op"] == "SQL") {
$cond = " $val[val]"; // SQL injection
} elseif ($val["op"] == "LIKE %%") {
$cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
- } elseif (!ereg('NULL$', $val["op"])) {
+ } elseif (!preg_match('~NULL$~', $val["op"])) {
$cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
}
if ($val["col"] != "") {
@@ -417,12 +417,12 @@ username.form['auth[driver]'].onchange();
// find anywhere
$cols = array();
foreach ($fields as $name => $field) {
- $is_text = ereg('char|text|enum|set', $field["type"]);
- if ((is_numeric($val["val"]) || !ereg('(^|[^o])int|float|double|decimal|bit', $field["type"]))
- && (!ereg("[\x80-\xFF]", $val["val"]) || $is_text)
+ $is_text = preg_match('~char|text|enum|set~', $field["type"]);
+ if ((is_numeric($val["val"]) || !preg_match('~(^|[^o])int|float|double|decimal|bit~', $field["type"]))
+ && (!preg_match("~[\x80-\xFF]~", $val["val"]) || $is_text)
) {
$name = idf_escape($name);
- $cols[] = ($jush == "sql" && $is_text && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
+ $cols[] = ($jush == "sql" && $is_text && !preg_match('~^utf8~', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
}
}
$return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
@@ -495,7 +495,7 @@ username.form['auth[driver]'].onchange();
$history = &get_session("queries");
$id = "sql-" . count($history[$_GET["db"]]);
if (strlen($query) > 1e6) {
- $query = ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
+ $query = preg_replace('~[\x80-\xFF]+$~', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
}
$history[$_GET["db"]][] = array($query, time()); // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"]
return " " . @date("H:i:s") . " " . lang('SQL command') . "" . shorten_utf8($query, 1000) . '