Adminer - Přizpůsobení
Adminer i Editor poskytují podporu pro rozšíření. Část výchozí funkcionality Admineru lze přepsat vlastním kódem. Jediné, co k tomu potřebujete, je definovat funkci adminer_object
, která vrací objekt rozšiřující základní třídu Adminer\Adminer
. Potom už jenom vložte původní adminer.php
nebo editor.php
:
<?php
function adminer_object() {
class AdminerSoftware extends Adminer\Adminer {
function name() {
// custom name in title and heading
return 'Software';
}
function permanentLogin() {
// key used for permanent login
return '0d5f38d23eacf0d0a70b14d7ed7eb0f9';
}
function credentials() {
// server, username and password for connecting to database
return array('localhost', 'ODBC', '');
}
function database() {
// database name, will be escaped by Adminer
return 'software';
}
function login($login, $password) {
// validate user submitted credentials
return ($login == 'admin' && $password == 'gjAl1anb');
}
function tableName($tableStatus) {
// tables without comments would return empty string and will be ignored by Adminer
return Adminer\h($tableStatus['Comment']);
}
function fieldName($field, $order = 0) {
// only columns with comments will be displayed and only the first five in select
return ($order <= 5 && !preg_match('~_(md5|sha1)$~', $field['field']) ? Adminer\h($field['comment']) : '');
}
}
return new AdminerSoftware;
}
include './editor.php';
Pokud chcete vytvořit přizpůsobení Adminer Editoru pro jiné ovladače než MySQL, tak musíte definovat vlastní metodu loginForm
a vyplnit pole auth[driver]
hodnotou svého ovladače (pgsql
, sqlite
, ...).
Obvykle byste také měli implementovat metodu database
.
Příklad: editor/sqlite.php.
Adminer podporuje také rozšíření, což jsou přizpůsobení připravená k použití.
Přehled API

Všechno je ve jmenném prostoru Adminer
.
Objekt může přepsat následující metody:
- string Adminer::name() - Name in title and navigation
- array Adminer::credentials() - Connection parameters
- array Adminer::connectSsl() - Get SSL connection options
- string Adminer::permanentLogin(bool $create) - Get key used for permanent login
- string Adminer::bruteForceKey() - Return key used to group brute force attacks; behind a reverse proxy, you want to return the last part of X-Forwarded-For
- string Adminer::serverName(string $server) - Get server name displayed in breadcrumbs
- string Adminer::database() - Identifier of selected database
- array Adminer::databases(bool $flush) - Get cached list of databases
- array Adminer::schemas() - Get list of schemas
- float Adminer::queryTimeout() - Specify limit for waiting on some slow queries like DB list
- null Adminer::headers() - Headers to send before HTML output
- array Adminer::csp() - Get Content Security Policy headers
- bool Adminer::head(bool $dark) - Print HTML code inside <head>
- array Adminer::css() - Get URLs of the CSS files
- null Adminer::loginForm() - Print login form
- string Adminer::loginFormField(string $name, string $heading, string $value) - Get login form field
- mixed Adminer::login(string $login, string $password) - Authorize the user
- string Adminer::tableName(array $tableStatus) - Table caption used in navigation and headings
- string Adminer::fieldName(array $field, int $order) - Field caption used in select and edit
- null Adminer::selectLinks(array $tableStatus, string $set) - Print links after select heading
- array Adminer::foreignKeys(string $table) - Get foreign keys for table
- array Adminer::backwardKeys(string $table, string $tableName) - Find backward keys for table
- null Adminer::backwardKeysPrint(array $backwardKeys, array $row) - Print backward keys for row
- string Adminer::selectQuery(string $query, float $start, bool $failed) - Query printed in select before execution
- string Adminer::sqlCommandQuery(string $query) - Query printed in SQL command before execution
- Adminer::sqlPrintAfter() - Print HTML code just before the Execute button in SQL command
- string Adminer::rowDescription(string $table) - Description of a row in a table
- array Adminer::rowDescriptions(array $rows, array $foreignKeys) - Get descriptions of selected data
- string Adminer::selectLink(string $val, array $field) - Get a link to use in select table
- string Adminer::selectVal(string $val, string $link, array $field, array $original) - Value printed in select table
- string Adminer::editVal(string $val, array $field) - Value conversion used in select and edit
- null Adminer::tableStructurePrint(array $fields, array $tableStatus) - Print table structure in tabular format
- null Adminer::tableIndexesPrint(array $indexes) - Print list of indexes on table in tabular format
- null Adminer::selectColumnsPrint(array $select, array $columns) - Print columns box in select
- null Adminer::selectSearchPrint(array $where, array $columns, array $indexes) - Print search box in select
- null Adminer::selectOrderPrint(array $order, array $columns, array $indexes) - Print order box in select
- null Adminer::selectLimitPrint(string $limit) - Print limit box in select
- null Adminer::selectLengthPrint(string $text_length) - Print text length box in select
- null Adminer::selectActionPrint(array $indexes) - Print action box in select
- bool Adminer::selectCommandPrint() - Print command box in select
- bool Adminer::selectImportPrint() - Print import box in select
- null Adminer::selectEmailPrint(array $emailFields, array $columns) - Print extra text in the end of a select form
- array Adminer::selectColumnsProcess(array $columns, array $indexes) - Process columns box in select
- array Adminer::selectSearchProcess(array $fields, array $indexes) - Process search box in select
- array Adminer::selectOrderProcess(array $fields, array $indexes) - Process order box in select
- string Adminer::selectLimitProcess() - Process limit box in select
- string Adminer::selectLengthProcess() - Process length box in select
- bool Adminer::selectEmailProcess(array $where, array $foreignKeys) - Process extras in select form
- string Adminer::selectQueryBuild(array $select, array $where, array $group, array $order, int $limit, int $page) - Build SQL query used in select
- string Adminer::messageQuery(string $query, string $time, bool $failed) - Query printed after execution in the message
- null Adminer::editRowPrint(string $table, array $fields, mixed $row, bool $update) - Print before edit form
- array Adminer::editFunctions(array $field) - Functions displayed in edit form
- string Adminer::editInput(string $table, array $field, string $attrs, string $value) - Get options to display edit field
- string Adminer::editHint(string $table, array $field, string $value) - Get hint for edit field
- string Adminer::processInput(array $field, string $value, string $function) - Process sent input
- array Adminer::dumpOutput() - Return export output options
- array Adminer::dumpFormat() - Return export format options
- null Adminer::dumpDatabase(string $db) - Export database structure
- null Adminer::dumpTable(string $table, string $style, int $is_view) - Export table structure
- null Adminer::dumpData(string $table, string $style, string $query) - Export table data
- string Adminer::dumpFilename(string $identifier) - Set export filename
- string Adminer::dumpHeaders(string $identifier, bool $multi_table) - Send headers for export
- null Adminer::dumpFooter() - Print text after export
- string Adminer::importServerPath() - Set the path of the file for webserver load
- bool Adminer::homepage() - Print homepage
- null Adminer::navigation(string $missing) - Print navigation after Adminer title
- Adminer::syntaxHighlighting(array $tables) - Set up syntax highlight for code and <textarea>
- null Adminer::databasesPrint(string $missing) - Print databases list in menu
- null Adminer::tablesPrint(array $tables) - Print table list in menu
Lze používat následující funkce ve jmenném prostoru Adminer
.
- Db connection() - Get database connection
- Adminer adminer() - Get Adminer object
- Driver driver() - Get Driver object
- string version() - Get Adminer version
- string idf_unescape(string $idf) - Unescape database identifier
- string q(string $string) - Shortcut for $connection->quote($string)
- string escape_string(string $val) - Escape string to use inside ''
- string number(string $val) - Remove non-digits from a string
- string number_type() - Get regular expression to match numeric types
- null remove_slashes(array $process, bool $filter) - Disable magic_quotes_gpc
- string bracket_escape(string $idf, bool $back) - Escape or unescape string to use inside form []
- bool min_version(string $version, string $maria_db, Db $connection2) - Check if connection has at least the given version
- string charset(Db $connection) - Get connection charset
- bool ini_bool(string $ini) - Get INI boolean value
- bool sid() - Check if SID is necessary
- null set_password(string $vendor, string $server, string $username, string $password) - Set password to session
- string get_password() - Get password from session
- string get_val(string $query, int $field) - Get single value from database
- array get_vals(string $query, mixed $column) - Get list of values from database
- array get_key_vals(string $query, Db $connection2, bool $set_keys) - Get keys from first column and values from second
- array get_rows(string $query, Db $connection2, string $error) - Get all rows of result
- array unique_array(array $row, array $indexes) - Find unique identifier of a row
- string escape_key(string $key) - Escape column key used in where()
- string where(array $where, array $fields) - Create SQL condition from parsed query string
- string where_check(string $val, array $fields) - Create SQL condition from query string
- string where_link(int $i, string $column, string $value, string $operator) - Create query string where condition from value
- string convert_fields(array $columns, array $fields, array $select) - Get select clause for convertible fields
- bool cookie(string $name, string $value, int $lifetime) - Set cookie valid on current path
- array get_settings(string $cookie) - Get settings stored in a cookie
- mixed get_setting(string $key, string $cookie) - Get setting stored in a cookie
- bool save_settings(array $settings, string $cookie) - Store settings to a cookie
- null restart_session() - Restart stopped session
- null stop_session(bool $force) - Stop session if possible
- mixed &(string $key) - Get session variable for current server
- mixed set_session(string $key, mixed $val) - Set session variable for current server
- string auth_url(string $vendor, string $server, string $username, string $db) - Get authenticated URL
- bool is_ajax() - Find whether it is an AJAX request
- null redirect(string $location, string $message) - Send Location header and exit
- bool query_redirect(string $query, string $location, string $message, bool $redirect, bool $execute, bool $failed, string $time) - Execute query and redirect if successful
- Result queries(string $query) - Execute and remember query
- bool apply_queries(string $query, array $tables, callback $escape) - Apply command to all array items
- bool queries_redirect(string $location, string $message, bool $redirect) - Redirect by remembered queries
- string format_time(float $start) - Format elapsed time
- string relative_uri() - Get relative REQUEST_URI
- string remove_from_uri(string $param) - Remove parameter from query string
- mixed get_file(string $key, bool $decompress, string $delimiter) - Get file contents from $_FILES
- string upload_error(int $error) - Determine upload error
- string repeat_pattern(string $pattern, int $length) - Create repeat pattern for preg
- bool is_utf8(string $val) - Check whether the string is in UTF-8
- string shorten_utf8(string $string, int $length, string $suffix) - Shorten UTF-8 string
- string format_number(int $val) - Format decimal number
- string friendly_url(string $val) - Generate friendly URL
- array table_status1(string $table, bool $fast) - Get status of a single table and fall back to name on error
- array column_foreign_keys(string $table) - Find out foreign keys for each column
- array fields_from_edit() - Compute fields() from $_POST edit data
- string dump_headers(string $identifier, bool $multi_table) - Send headers for export
- null dump_csv(array $row) - Print CSV row
- string apply_sql_function(string $function, string $column) - Apply SQL function
- string get_temp_dir() - Get path of the temporary directory
- resource file_open_lock(string $filename) - Open and exclusively lock a file
- file_write_unlock(resource $fp, string $data) - Write and unlock a file
- file_unlock(resource $fp) - Unlock and close a file
- mixed first(array $array) - Get first element of an array
- string password_file(bool $create) - Read password from file adminer.key in temporary directory or create one
- string rand_string() - Get a random string
- string select_value(string $val, string $link, array $field, int $text_length) - Format value to use in select
- bool is_mail(string $email) - Check whether the string is e-mail address
- bool is_url(string $string) - Check whether the string is URL address
- bool is_shortable(array $field) - Check if field should be shortened
- string count_rows(string $table, array $where, bool $is_group, array $group) - Get query to compute number of found rows
- array slow_query(string $query) - Run query which can be killed by AJAX call after timing out
- string get_token() - Generate BREACH resistant CSRF token
- bool verify_token() - Verify if supplied CSRF token is valid
Pomůcky pro HTML:
- string script(string $source, string $trailing) - Return <script> element
- string script_src(string $url) - Return <script src> element
- string nonce() - Get a nonce="" attribute with CSP nonce
- string input_hidden(string $name, string $value) - Get <input type="hidden">
- string input_token(string $special) - Get <input type="hidden" name="token">
- string target_blank() - Get a target="_blank" attribute
- string h(string $string) - Escape for HTML
- string nl_br(string $string) - Convert \n to <br>
- string checkbox(string $name, string $value, bool $checked, string $label, string $onclick, string $class, string $labelled_by) - Generate HTML checkbox
- string optionlist(array $options, mixed $selected, bool $use_keys) - Generate list of HTML options
- string html_select(string $name, array $options, string $value, string $onchange, string $labelled_by) - Generate HTML <select>
- string html_radios(string $name, array $options, string $value) - Generate HTML radio list
- string confirm(string $message, string $selector) - Get onclick confirmation
- null print_fieldset(string $id, string $legend, bool $visible) - Print header for hidden fieldset (close by </div></fieldset>)
- string bold(bool $bold, string $class) - Return class='active' if $bold is true
- string js_escape(string $string) - Escape string for JavaScript apostrophes
- string pagination(int $page, int $current) - Generate page number for pagination
- bool hidden_fields(array $process, array $ignore) - Print hidden fields
- null hidden_fields_get() - Print hidden fields for GET forms
- null enum_input(string $type, string $attrs, array $field, mixed $value, string $empty) - Print enum or set input field
- null input(array $field, mixed $value, string $function, bool $autofocus) - Print edit input field
- string process_input(one $field) - Process edit input field
- null search_tables() - Print results of search in all tables
- string on_help(string $command, bool $side) - Return events to display help on mouse over
- null edit_form(string $table, array $fields, mixed $row, bool $update) - Print edit data form
Funkce specifické pro překlady:
- string get_lang() - Get current language
Funkce specifické pro ovladač:
- Db::connect( $server, $username, $password, $database, $port, $socket) - @see https://php.net/mysqli.construct */
- bool Db::connect(string $server, string $username, string $password) - Connect to server
- bool Db::set_charset(string $charset) - Set the client character set
- string Db::quote(string $string) - Quote string to use in SQL
- bool Db::select_db(string $database) - Select database
- mixed Db::query(string $query, bool $unbuffered) - Send query
- bool Db::multi_query(string $query) - Send query with more resultsets
- Result Db::store_result() - Get current resultset
- bool Db::next_result() - Fetch next resultset
- string Db::result(string $query, int $field) - Get single field from result
- Result::__construct(resource $result) - Constructor
- array Result::fetch_assoc() - Fetch next row as associative array
- array Result::fetch_row() - Fetch next row as numbered array
- string Result::fetch_column(int $field) - Fetch a single column
- object Result::fetch_field() - Fetch next field
- Result::__destruct() - Free result set
- string idf_escape(string $idf) - Escape database identifier
- string table(string $idf) - Get escaped table name
- mixed connect(array $credentials) - Connect to the database
- array get_databases(bool $flush) - Get cached list of databases
- string limit(string $query, string $where, int $limit, int $offset, string $separator) - Formulate SQL query with limit
- string limit1(string $table, string $query, string $where, string $separator) - Formulate SQL modification query with limit 1
- string db_collation(string $db, array $collations) - Get database collation
- string logged_user() - Get logged user
- array tables_list() - Get tables list
- array count_tables(array $databases) - Count tables in all databases
- array table_status(string $name, bool $fast) - Get table status
- bool is_view(array $table_status) - Find out whether the identifier is view
- bool fk_support(array $table_status) - Check if table supports foreign keys
- array fields(string $table) - Get information about fields
- array indexes(string $table, string $connection2) - Get table indexes
- array foreign_keys(string $table) - Get foreign keys in table
- array view(string $name) - Get view SELECT
- array collations() - Get sorted grouped list of collations
- bool information_schema(string $db) - Find out if database is information_schema
- string error() - Get escaped error message
- string create_database(string $db, string $collation) - Create database
- bool drop_databases(array $databases) - Drop databases
- bool rename_database(string $name, string $collation) - Rename database from DB
- string auto_increment() - Generate modifier for auto increment column
- bool alter_table(string $table, string $name, array $fields, array $foreign, string $comment, string $engine, string $collation, string $auto_increment, string $partitioning) - Run commands to create or alter table
- bool alter_indexes(string $table, array $alter) - Run commands to alter indexes
- bool truncate_tables(array $tables) - Run commands to truncate tables
- bool drop_views(array $views) - Drop views
- bool drop_tables(array $tables) - Drop tables
- bool move_tables(array $tables, array $views, string $target) - Move tables to other schema
- bool copy_tables(array $tables, array $views, string $target) - Copy tables to other schema
- array trigger(string $name) - Get information about trigger
- array triggers(string $table) - Get defined triggers
- array trigger_options() - Get trigger options
- array routine(string $name, string $type) - Get information about stored routine
- array routines() - Get list of routines
- array routine_languages() - Get list of available routine languages
- string routine_id(string $name, array $row) - Get routine signature
- string last_id(Result $result) - Get last auto increment ID
- Result explain(Db $connection, string $query) - Explain select
- int found_rows(array $table_status, array $where) - Get approximate number of rows
- string create_sql(string $table, bool $auto_increment, string $style) - Get SQL command to create table
- string truncate_sql(string $table) - Get SQL command to truncate table
- string use_sql(string $database) - Get SQL command to change database
- string trigger_sql(string $table) - Get SQL commands to create triggers
- array show_variables() - Get server variables
- array show_status() - Get status variables
- array process_list() - Get process list
- string convert_field(array $field) - Convert field in select and edit
- string unconvert_field(array $field, string $return) - Convert value in edit after applying functions back
- bool support(string $feature) - Check whether a feature is supported
- bool kill_process(int $val) - Kill a process
- string connection_id() - Return query to get connection ID
- int max_connections() - Get maximum number of connections
Driver:
- null add_driver(string $id, string $name) - Add a driver
- string get_driver(string $id) - Get driver name
- Driver::__construct(Db $connection) - Create object for performing database operations
- array Driver::types() - Get all types
- array Driver::structuredTypes() - Get structured types
- string Driver::enumLength(array $field) - Get enum values
- string Driver::unconvertFunction(array $field) - Function used to convert the value inputted by user
- Result Driver::select(string $table, array $select, array $where, array $group, array $order) - Select data from table
- bool Driver::delete(string $table, string $queryWhere, int $limit) - Delete data from table
- bool Driver::update(string $table, array $set, string $queryWhere, int $limit, string $separator) - Update data in table
- bool Driver::insert(string $table, array $set) - Insert data into table
- string Driver::insertReturning(string $table) - Get RETURNING clause for INSERT queries, PostgreSQL specific
- bool Driver::insertUpdate(string $table, array $rows, array $primary) - Insert or update data in table
- bool Driver::begin() - Begin transaction
- bool Driver::commit() - Commit transaction
- bool Driver::rollback() - Rollback transaction
- string Driver::slowQuery(string $query, int $timeout) - Return query with a timeout
- string Driver::convertSearch(string $idf, array $val, array $field) - Convert column to be searchable
- string Driver::convertOperator(string $operator) - Convert operator so it can be used in search
- string Driver::value(string $val, array $field) - Convert value returned by database to actual value
- string Driver::quoteBinary(string $s) - Quote binary string
- string Driver::warnings() - Get warnings about the last command
- string Driver::tableHelp(string $name, bool $is_view) - Get help link for table
- bool Driver::hasCStyleEscapes() - Check if C-style escapes are supported
- array Driver::engines() - Get supported engines
- bool Driver::supportsIndex(array $table_status) - Check whether table supports indexes
- array Driver::checkConstraints(string $table) - Get defined check constraints
Funkce specifické pro Adminer:
- array select(Result $result, Db $connection2, array $orgtables) - Print select result
- array referencable_primary(string $self) - Get referencable tables with single column primary key except self
- null textarea(string $name, string $value, int $rows, int $cols) - Print SQL <textarea> tag
- string select_input(string $attrs, array $options, string $value, string $onchange, string $placeholder) - Generate HTML <select> or <input> if $options are empty
- null json_row(string $key, string $val) - Print one row in JSON object
- null edit_type(string $key, array $field, array $collations, array $foreign_keys) - Print table columns for type edit
- array get_partitions_info(string $table) - Get partition info
- string process_length(string $length) - Filter length value including enums
- string process_type(array $field, string $collate) - Create SQL string from field type
- array process_field(array $field, array $type_field) - Create SQL string from field
- string default_value(array $field) - Get default value clause
- string type_class(string $type) - Get type class to use in CSS
- null edit_fields(array $fields, array $collations, string $type, array $foreign_keys) - Print table interior for fields editing
- bool process_fields(array $fields) - Move fields up and down or add field
- string normalize_enum(array $match) - Callback used in routine()
- bool grant(string $grant, array $privileges, string $columns, string $on) - Issue grant or revoke commands
- null drop_create(string $drop, string $create, string $drop_created, string $test, string $drop_test, string $location, string $message_drop, string $message_alter, string $message_create, string $old_name, string $new_name) - Drop old object and create a new one
- string create_trigger(string $on, array $row) - Generate SQL query for creating trigger
- string create_routine(string $routine, array $row) - Generate SQL query for creating routine
- string remove_definer(string $query) - Remove current user definer from SQL command
- string format_foreign_key(array $foreign_key) - Format foreign key to use in SQL query
- null tar_file(string $filename, TmpFile $tmp_file) - Add a file to TAR
- int ini_bytes(string $ini) - Get INI bytes value
- string doc_link(array $paths, string $text) - Create link to database documentation
- string db_size(string $db) - Compute size of database
- null set_utf8mb4(string $create) - Print SET NAMES if utf8mb4 might be needed
Funkce specifické pro Editor:
- string email_header(string $header) - Encode e-mail header in UTF-8
- bool send_mail(string $email, string $subject, string $message, string $from, array $files) - Send e-mail in UTF-8
- bool like_bool(array $field) - Check whether the column looks like boolean
Type aliases:
- TableStatus: array{Name:string, Engine:string, Comment:string, Oid:int, Rows:int, Collation:string, Auto_increment:int, Data_length:int, Index_length:int, Data_free:int}
- Field: array{field:string, full_type:string, type:string, length:int, unsigned:string, default:string, null:bool, auto_increment:bool, on_update:string, collation:string, privileges:int[], comment:string, primary:bool, generated:string}
- Index: array{type:string, columns:list<string>, lengths:list<int>, descs:list<bool>}
- ForeignKey: array{db:string, ns:string, table:string, source:list<string>, target:list<string>, on_delete:string, on_update:string}
- Trigger: array{Trigger:string, Timing:string, Event:string, Of:string, Type:string, Statement:string}
- Routine: array{fields:list<array{field:string, type:string, length:string, unsigned:string, null:bool, full_type:string, inout:string, collation:string}>, comment:string, returns:array, definition:string, language:string}
- BackwardKey: array{name:string, keys:string[][]}