return (bool) $this->link;
}
- /** Set the client character set
- */
+ /** Set the client character set */
function set_charset(string $charset): bool {
if (function_exists('mysql_set_charset')) {
if (mysql_set_charset($charset, $this->link)) {
/** @var resource */ private $result;
/** @var int */ private $offset = 0;
- /** Constructor
- */
function __construct(resource $result) {
$this->result = $result;
$this->num_rows = mysql_num_rows($result);
return $return;
}
- /** Free result set
- */
+ /** Free result set */
function __destruct() {
mysql_free_result($this->result);
}
- /** Escape database identifier
- */
+ /** Escape database identifier */
function idf_escape(string $idf): string {
return "`" . str_replace("`", "``", $idf) . "`";
}
- /** Get escaped table name
- */
+ /** Get escaped table name */
function table(string $idf): string {
return idf_escape($idf);
}
return $return;
}
- /** Get logged user
- */
+ /** Get logged user */
function logged_user(): string {
return get_val("SELECT USER()");
}
return $return;
}
- /** Find out if database is information_schema
- */
+ /** Find out if database is information_schema */
function information_schema(string $db): bool {
return ($db == "information_schema")
|| (min_version(5.5) && $db == "performance_schema");
}
- /** Get escaped error message
- */
+ /** Get escaped error message */
function error(): string {
global $connection;
return h(preg_replace('~^You have an error.*syntax to use~U', "Syntax error", $connection->error));
return $return;
}
- /** Generate modifier for auto increment column
- */
+ /** Generate modifier for auto increment column */
function auto_increment(): string {
$auto_increment_index = " PRIMARY KEY";
// don't overwrite primary key by auto_increment
return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]);
}
- /** Get SQL command to create table
- */
+ /** Get SQL command to create table */
function create_sql(string $table, bool $auto_increment, string $style): string {
$return = get_val("SHOW CREATE TABLE " . table($table), 1);
if (!$auto_increment) {
return $return;
}
- /** Get SQL command to truncate table
- */
+ /** Get SQL command to truncate table */
function truncate_sql(string $table): string {
return "TRUNCATE " . table($table);
}
- /** Get SQL command to change database
- */
+ /** Get SQL command to change database */
function use_sql(string $database): string {
return "USE " . idf_escape($database);
}
- /** Get SQL commands to create triggers
- */
+ /** Get SQL commands to create triggers */
function trigger_sql(string $table): string {
$return = "";
foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_\\")), null, "-- ") as $row) {
return queries("KILL " . number($val));
}
- /** Return query to get connection ID
- */
+ /** Return query to get connection ID */
function connection_id(): string {
return "SELECT CONNECTION_ID()";
}
return array();
}
- /** Get values of user defined type
- */
+ /** Get values of user defined type */
function type_values(int $id): string {
return "";
}
return array();
}
- /** Get current schema
- */
+ /** Get current schema */
function get_schema(): string {
return "";
}
- /** Set current schema
- */
+ /** Set current schema */
function set_schema(string $schema, Db $connection2 = null): bool {
return true;
}
return password_file($create);
}
- /** Return key used to group brute force attacks; behind a reverse proxy, you want to return the last part of X-Forwarded-For
- */
+ /** Return key used to group brute force attacks; behind a reverse proxy, you want to return the last part of X-Forwarded-For */
function bruteForceKey(): string {
return $_SERVER["REMOTE_ADDR"];
}
return h($server);
}
- /** Identifier of selected database
- */
+ /** Identifier of selected database */
function database(): string {
// should be used everywhere instead of DB
return DB;
return 2;
}
- /** Headers to send before HTML output
- */
+ /** Headers to send before HTML output */
function headers(): void {
}
return $return;
}
- /** Print login form
- */
+ /** Print login form */
function loginForm(): void {
global $drivers;
echo "<table class='layout'>\n";
return shorten_utf8(trim($query), 1000);
}
- /** Print HTML code just before the Execute button in SQL command
- */
+ /** Print HTML code just before the Execute button in SQL command */
function sqlPrintAfter(): void {
}
);
}
- /** Print databases list in menu
- */
+ /** Print databases list in menu */
function databasesPrint(string $missing): void {
global $adminer, $connection;
$databases = $this->databases();
/** @var string */ public $error; // last error message
/** @var Result|bool */ protected $multi; // used for multiquery
- /** Connect to server
- */
+ /** Connect to server */
abstract function connect(string $server, string $username, string $password): bool;
/** Quote string to use in SQL
*/
abstract function quote(string $string): string;
- /** Select database
- */
+ /** Select database */
abstract function select_db(string $database): bool;
/** Send query
return $this->multi;
}
- /** Fetch next resultset
- */
+ /** Fetch next resultset */
function next_result(): bool {
return false;
}
define('Adminer\PAGE_HEADER', 1);
}
-/** Send HTTP headers
-*/
+/** Send HTTP headers */
function page_headers(): void {
global $adminer;
header("Content-Type: text/html; charset=utf-8");
return $nonce;
}
-/** Print flash and error messages
-*/
+/** Print flash and error messages */
function page_messages(string $error): void {
global $adminer;
$uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
$drivers = array();
-/** Add a driver
-*/
+/** Add a driver */
function add_driver(string $id, string $name): void {
global $drivers;
$drivers[$id] = $name;
}
-/** Get driver name
-*/
+/** Get driver name */
function get_driver(string $id): string {
global $drivers;
return $drivers[$id];
/** @var string */ public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; // regular expression for parsing enum lengths
/** @var list<string> */ public $generated = array(); // allowed types of generated columns
- /** Create object for performing database operations
- */
+ /** Create object for performing database operations */
function __construct(Db $connection) {
$this->conn = $connection;
}
) . $this->insertReturning($table));
}
- /** Get RETURNING clause for INSERT queries (PostgreSQL specific)
- */
+ /** Get RETURNING clause for INSERT queries (PostgreSQL specific) */
function insertReturning(string $table): string {
return "";
}
return $idf;
}
- /** Convert operator so it can be used in search
- */
+ /** Convert operator so it can be used in search */
function convertOperator(string $operator): string {
return $operator;
}
);
}
- /** Quote binary string
- */
+ /** Quote binary string */
function quoteBinary(string $s): string {
return q($s);
}
function tableHelp(string $name, bool $is_view = false) {
}
- /** Check if C-style escapes are supported
- */
+ /** Check if C-style escapes are supported */
function hasCStyleEscapes(): bool {
return false;
}
return $return;
}
-/** Filter length value including enums
-*/
+/** Filter length value including enums */
function process_length(string $length): string {
global $driver;
$enum_length = $driver->enumLength;
;
}
-/** Remove current user definer from SQL command
-*/
+/** Remove current user definer from SQL command */
function remove_definer(string $query): string {
return preg_replace('~^([A-Z =]+) DEFINER=`' . preg_replace('~@(.*)~', '`@`(%|\1)', logged_user()) . '`~', '\1', $query); //! proper escaping of user
}
echo str_repeat("\0", 511 - ($tmp_file->size + 511) % 512);
}
-/** Get INI bytes value
-*/
+/** Get INI bytes value */
function ini_bytes(string $ini): int {
$val = ini_get($ini);
switch (strtolower(substr($val, -1))) {
return format_number($return);
}
-/** Print SET NAMES if utf8mb4 might be needed
-*/
+/** Print SET NAMES if utf8mb4 might be needed */
function set_utf8mb4(string $create): void {
global $connection;
static $set = false;
// This file is used both in Adminer and Adminer Editor.
-/** Get database connection
-*/
+/** Get database connection */
function connection(): Db {
// can be used in customization, $connection is minified
global $connection;
return $driver;
}
-/** Get Adminer version
-*/
+/** Get Adminer version */
function version(): string {
global $VERSION;
return $VERSION;
return str_replace($last . $last, $last, substr($idf, 1, -1));
}
-/** Shortcut for $connection->quote($string)
-*/
+/** Shortcut for $connection->quote($string) */
function q(string $string): string {
global $connection;
return $connection->quote($string);
}
-/** Escape string to use inside ''
-*/
+/** Escape string to use inside '' */
function escape_string(string $val): string {
return substr(q($val), 1, -1);
}
return ($array && array_key_exists($key, $array) ? $array[$key] : $default);
}
-/** Remove non-digits from a string
-*/
+/** Remove non-digits from a string */
function number(string $val): string {
return preg_replace('~[^0-9]+~', '', $val);
}
-/** Get regular expression to match numeric types
-*/
+/** Get regular expression to match numeric types */
function number_type(): string {
return '((?<!o)int(?!er)|numeric|real|float|double|decimal|money)'; // not point, not interval
}
}
}
-/** Escape or unescape string to use inside form []
-*/
+/** Escape or unescape string to use inside form [] */
function bracket_escape(string $idf, bool $back = false): string {
// escape brackets inside name="x[]"
static $trans = array(':' => ':1', ']' => ':2', '[' => ':3', '"' => ':4');
return $version && version_compare($server_info, $version) >= 0;
}
-/** Get connection charset
-*/
+/** Get connection charset */
function charset(Db $connection): string {
return (min_version("5.5.3", 0, $connection) ? "utf8mb4" : "utf8"); // SHOW CHARSET would require an extra query
}
-/** Get INI boolean value
-*/
+/** Get INI boolean value */
function ini_bool(string $ini): bool {
$val = ini_get($ini);
return (preg_match('~^(on|true|yes)$~i', $val) || (int) $val); // boolean values set by php_value are strings
}
-/** Check if SID is necessary
-*/
+/** Check if SID is necessary */
function sid(): bool {
static $return;
if ($return === null) { // restart_session() defines SID
return $return;
}
-/** Set password to session
-*/
+/** Set password to session */
function set_password(string $vendor, string $server, string $username, ?string $password): void {
$_SESSION["pwds"][$vendor][$server][$username] = ($_COOKIE["adminer_key"] && is_string($password)
? array(encrypt_string($password, $_COOKIE["adminer_key"]))
}
}
-/** Escape column key used in where()
-*/
+/** Escape column key used in where() */
function escape_key(string $key): string {
if (preg_match('(^([\w(]+)(' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . ')([ \w)]+)$)', $key, $match)) { //! columns looking like functions
return $match[1] . idf_escape(idf_unescape($match[2])) . $match[3]; //! SQL injection
cookie($cookie, http_build_query($settings + get_settings($cookie)));
}
-/** Restart stopped session
-*/
+/** Restart stopped session */
function restart_session(): void {
if (!ini_bool("session.use_cookies") && (!function_exists('session_status') || session_status() == 1)) { // 1 - PHP_SESSION_NONE, session_status() available since PHP 5.4
session_start();
}
}
-/** Stop session if possible
-*/
+/** Stop session if possible */
function stop_session(bool $force = false): void {
$use_cookies = ini_bool("session.use_cookies");
if (!$use_cookies || $force) {
$_SESSION[$key][DRIVER][SERVER][$_GET["username"]] = $val; // used also in auth.inc.php
}
-/** Get authenticated URL
-*/
+/** Get authenticated URL */
function auth_url(string $vendor, string $server, string $username, string $db = null): string {
global $drivers;
$uri = remove_from_uri(implode("|", array_keys($drivers))
;
}
-/** Find whether it is an AJAX request
-*/
+/** Find whether it is an AJAX request */
function is_ajax(): bool {
return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest");
}
}
}
-/** Execute query and redirect if successful
-*/
+/** Execute query and redirect if successful */
function query_redirect(string $query, string $location, string $message, bool $redirect = true, bool $execute = true, bool $failed = false, string $time = ""): bool {
global $connection, $error, $adminer;
if ($execute) {
return true;
}
-/** Redirect by remembered queries
-*/
+/** Redirect by remembered queries */
function queries_redirect(string $location, string $message, bool $redirect): bool {
$queries = implode("\n", Queries::$queries);
$time = format_time(Queries::$start);
return lang('%.3f s', max(0, microtime(true) - $start));
}
-/** Get relative REQUEST_URI
-*/
+/** Get relative REQUEST_URI */
function relative_uri(): string {
return str_replace(":", "%3a", preg_replace('~^[^?]*/([^?]*)~', '\1', $_SERVER["REQUEST_URI"]));
}
-/** Remove parameter from query string
-*/
+/** Remove parameter from query string */
function remove_from_uri(string $param = ""): string {
return substr(preg_replace("~(?<=[?&])($param" . (SID ? "" : "|" . session_name()) . ")=[^&]*&~", '', relative_uri() . "&"), 0, -1);
}
return $return;
}
-/** Determine upload error
-*/
+/** Determine upload error */
function upload_error(int $error): string {
$max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : 0); // post_max_size is checked in index.php
return ($error ? lang('Unable to upload a file.') . ($max_size ? " " . lang('Maximum allowed file size is %sB.', $max_size) : "") : lang('File does not exist.'));
}
-/** Create repeat pattern for preg
-*/
+/** Create repeat pattern for preg */
function repeat_pattern(string $pattern, int $length): string {
// fix for Compilation failed: number too big in {} quantifier
return str_repeat("$pattern{0,65535}", $length / 65535) . "$pattern{0," . ($length % 65535) . "}"; // can create {0,0} which is OK
}
-/** Check whether the string is in UTF-8
-*/
+/** Check whether the string is in UTF-8 */
function is_utf8(string $val): bool {
// don't print control chars except \t\r\n
return (preg_match('~~u', $val) && !preg_match('~[\0-\x8\xB\xC\xE-\x1F]~', $val));
return strtr(number_format($val, 0, ".", lang(',')), preg_split('~~u', lang('0123456789'), -1, PREG_SPLIT_NO_EMPTY));
}
-/** Generate friendly URL
-*/
+/** Generate friendly URL */
function friendly_url(string $val): string {
// used for blobs and export
return preg_replace('~\W~i', '-', $val);
return ($function ? ($function == "unixepoch" ? "DATETIME($column, '$function')" : ($function == "count distinct" ? "COUNT(DISTINCT " : strtoupper("$function(")) . "$column)") : $column);
}
-/** Get path of the temporary directory
-*/
+/** Get path of the temporary directory */
function get_temp_dir(): string {
$return = ini_get("upload_tmp_dir"); // session_save_path() may contain other storage path
if (!$return) {
return $fp;
}
-/** Write and unlock a file
-*/
+/** Write and unlock a file */
function file_write_unlock(resource $fp, string $data): void {
rewind($fp);
fwrite($fp, $data);
file_unlock($fp);
}
-/** Unlock and close a file
-*/
+/** Unlock and close a file */
function file_unlock(resource $fp): void {
flock($fp, LOCK_UN);
fclose($fp);
return $adminer->selectVal($return, $link, $field, $val);
}
-/** Check whether the string is e-mail address
-*/
+/** Check whether the string is e-mail address */
function is_mail(?string $email): bool {
$atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name
$domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component
return is_string($email) && preg_match("(^$pattern(,\\s*$pattern)*\$)i", $email);
}
-/** Check whether the string is URL address
-*/
+/** Check whether the string is URL address */
function is_url(string $string): bool {
$domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component //! IDN
return preg_match("~^(https?)://($domain?\\.)+$domain(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i", $string); //! restrict path, query and fragment characters
return $return;
}
-/** Generate BREACH resistant CSRF token
-*/
+/** Generate BREACH resistant CSRF token */
function get_token(): string {
$rand = rand(1, 1e6);
return ($rand ^ $_SESSION["token"]) . ":$rand";
}
-/** Verify if supplied CSRF token is valid
-*/
+/** Verify if supplied CSRF token is valid */
function verify_token(): bool {
list($token, $rand) = explode(":", $_POST["token"]);
return ($rand ^ $_SESSION["token"]) == $token;
}
// used in compiled version
-/**
-*/
function lzw_decompress(string $binary): string {
// convert binary string to codes
$dictionary_count = 256;
<?php
namespace Adminer;
-/** Return <script> element
-*/
+/** Return <script> element */
function script(string $source, string $trailing = "\n"): string {
return "<script" . nonce() . ">$source</script>$trailing";
}
-/** Return <script src> element
-*/
+/** Return <script src> element */
function script_src(string $url): string {
return "<script src='" . h($url) . "'" . nonce() . "></script>\n";
}
-/** Get a nonce="" attribute with CSP nonce
-*/
+/** Get a nonce="" attribute with CSP nonce */
function nonce(): string {
return ' nonce="' . get_nonce() . '"';
}
return input_hidden("token", ($special ?: $token));
}
-/** Get a target="_blank" attribute
-*/
+/** Get a target="_blank" attribute */
function target_blank(): string {
return ' target="_blank" rel="noreferrer noopener"';
}
-/** Escape for HTML
-*/
+/** Escape for HTML */
function h(string $string): string {
return str_replace("\0", "�", htmlspecialchars($string, ENT_QUOTES, 'utf-8'));
}
-/** Convert \n to <br>
-*/
+/** Convert \n to <br> */
function nl_br(string $string): string {
return str_replace("\n", "<br>", $string); // nl2br() uses XHTML before PHP 5.3
}
return $return;
}
-/** Get onclick confirmation
-*/
+/** Get onclick confirmation */
function confirm(string $message = "", string $selector = "qsl('input')"): string {
return script("$selector.onclick = () => confirm('" . ($message ? js_escape($message) : lang('Are you sure?')) . "');", "");
}
-/** Print header for hidden fieldset (close by </div></fieldset>)
-*/
+/** Print header for hidden fieldset (close by </div></fieldset>) */
function print_fieldset(string $id, string $legend, bool $visible = false): void {
echo "<fieldset><legend>";
echo "<a href='#fieldset-$id'>$legend</a>";
echo "<div id='fieldset-$id'" . ($visible ? "" : " class='hidden'") . ">\n";
}
-/** Return class='active' if $bold is true
-*/
+/** Return class='active' if $bold is true */
function bold(bool $bold, string $class = ""): string {
return ($bold ? " class='active $class'" : ($class ? " class='$class'" : ""));
}
-/** Escape string for JavaScript apostrophes
-*/
+/** Escape string for JavaScript apostrophes */
function js_escape(string $string): string {
return addcslashes($string, "\r\n'\\/"); // slash for <script>
}
-/** Generate page number for pagination
-*/
+/** Generate page number for pagination */
function pagination(int $page, int $current): string {
return " " . ($page == $current
? $page + 1
return $return;
}
-/** Print hidden fields for GET forms
-*/
+/** Print hidden fields for GET forms */
function hidden_fields_get(): void {
echo (sid() ? input_hidden(session_name(), session_id()) : '');
echo (SERVER !== null ? input_hidden(DRIVER, SERVER) : "");
echo "</form>\n";
}
-/** Get button with icon
-*/
+/** Get button with icon */
function icon(string $icon, string $name, string $html, string $title): string {
return "<button type='submit' name='$name' title='" . h($title) . "' class='icon icon-$icon'><span>$html</span></button>";
}
'zh-tw' => '繁體中文', // http://tzangms.com
);
-/** Get current language
-*/
+/** Get current language */
function get_lang(): string {
global $LANG;
return $LANG;
$this->handler = tmpfile();
}
- /**
- */
function write(string $contents): void {
$this->size += strlen($contents);
fwrite($this->handler, $contents);
* @link http://www.coolcode.cn/?action=show&id=128
*/
-/**
-*/
function int32(int $n): int {
while ($n >= 2147483648) {
$n -= 4294967296;
return $v;
}
-/**
-*/
function xxtea_mx(int $z, int $y, int $sum, int $k): int {
return int32((($z >> 5 & 0x7FFFFFF) ^ $y << 2) + (($y >> 3 & 0x1FFFFFFF) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k ^ $z));
}
<?php
namespace Adminer;
-/** Encode e-mail header in UTF-8
-*/
+/** Encode e-mail header in UTF-8 */
function email_header(string $header): string {
// iconv_mime_encode requires iconv, imap_8bit requires IMAP extension
return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
return $this->rootQuery($path, $content, $method);
}
- /**
- */
function connect(string $server, string $username, string $password): bool {
preg_match('~^(https?://)?(.*)~', $server, $match);
$this->url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
class AdminerLoginTable {
protected $database;
- /** Set database of login table
- */
+ /** Set database of login table */
function __construct(string $database) {
$this->database = $database;
}
class AdminerTinymce {
protected $path;
- /**
- */
function __construct(string $path = "tiny_mce/tiny_mce.js") {
$this->path = $path;
}