class Util

Misc functions used all over the scripts.

Methods

static boolean
showIcons(string $value)

Checks whether configuration value tells to show icons.

static boolean
showText(string $value)

Checks whether configuration value tells to show text.

static string
getIcon(string $icon, string $alternate = '', boolean $force_text = false, boolean $menu_icon = false, string $control_param = 'ActionLinksMode')

Returns an HTML IMG tag for a particular icon from a theme, which may be an actual file or an icon from a sprite.

static string
getImage(string $image, string $alternate = '', array $attributes = [])

Returns an HTML IMG tag for a particular image from a theme

static string
getFormattedMaximumUploadSize(integer $max_upload_size)

Returns the formatted maximum size for an upload

static string
generateHiddenMaxFileSize(integer $max_size)

Generates a hidden field which should indicate to the browser the maximum size for upload

static string
escapeMysqlWildcards(string $name)

Add slashes before "_" and "%" characters for using them in MySQL database, table and field names.

static string
unescapeMysqlWildcards(string $name)

removes slashes before "_" and "%" characters Note: This function does not unescape backslashes!

static string
unQuote(string $quoted_string, string $quote = null)

removes quotes (',",`) from a quoted string

static string
formatSql(string $sqlQuery, boolean $truncate = false)

format sql strings

static string
showCopyToClipboard(string $text)

Displays a button to copy content to clipboard

static string
showDocLink(string $link, string $target = 'documentation', boolean $bbcode = false)

Displays a link to the documentation as an icon

static string
getMySQLDocuURL(string $link, string $anchor = '')

Get a URL link to the official MySQL documentation

static string
linkToVarDocumentation(string $name, bool $useMariaDB = false, string $text = null)

Get a link to variable documentation

static string
showMySQLDocu(string $link, bool $bigIcon = false, string|null $url = null, string|null $text = null, string $anchor = '')

Displays a link to the official MySQL documentation

static string
getDocuLink(string $page, string $anchor = '')

Returns link to documentation.

static string
showDocu(string $page, string $anchor = '', boolean $bbcode = false)

Displays a link to the phpMyAdmin documentation

static string
showPHPDocu(string $target)

Displays a link to the PHP documentation

static string
showHint(string $message)

Returns HTML code for a tooltip

static string
mysqlDie(string|bool $server_msg = '', string $sql_query = '', bool $is_modify_link = true, string $back_url = '', bool $exit = true)

Displays a MySQL error message in the main panel when $exit is true.

static array
getTableList(string $db, string $tables = null, integer $limit_offset = 0, int|bool $limit_count = false)

returns array with tables of given db with extended information and grouped

static mixed
backquote(mixed $a_name, boolean $do_it = true)

Adds backquotes on both sides of a database, table or field name.

static mixed
backquoteCompat(mixed $a_name, string $compatibility = 'MSSQL', boolean $do_it = true)

Adds backquotes on both sides of a database, table or field name.

static string
getMessage(Message|string $message, string $sql_query = null, string $type = 'notice')

Prepare the message and the query usually the message is the result of the query executed

static boolean
profilingSupported()

Verifies if current MySQL server supports profiling

static array|null
formatByteDown(double|int $value, int $limes = 6, int $comma = 0)

Formats $value to byte view

static string
formatNumber(double $value, integer $digits_left = 3, integer $digits_right = 0, boolean $only_down = false, boolean $noTrailingZero = true)

Formats $value to the given length and appends SI prefixes with a $length of 0 no truncation occurs, number is only formatted to the current locale

static integer
extractValueFromFormattedSize(string $formatted_size)

Returns the number of bytes when a formatted size is given

static string
localisedDate(integer $timestamp = -1, string $format = '')

Writes localised date

static string
getHtmlTab(array $tab, array $url_params = [])

returns a tab for tabbed navigation.

static string
getHtmlTabs(array $tabs, array $url_params, string $menu_id, bool $resizable = false)

returns html-code for a tab navigation

static string
linkOrButton(string $url, string $message, mixed $tag_params = [], string $target = '')

Displays a link, or a link with code to trigger POST request.

static array
splitURLQuery(string $url)

Splits a URL string by parameter

static string
timespanFormat(int $seconds)

Returns a given timespan value in a readable format.

static void
checkParameters(string[] $params, boolean $request = false)

Function added to avoid path disclosures.

static array
getUniqueCondition(resource $handle, integer $fields_cnt, array $fields_meta, array $row, boolean $force_unique = false, string|boolean $restrict_to_table = false, array|null $analyzed_sql_results = null)

Function to generate unique condition for specified row.

static string
getCharsetQueryPart(string $collation, boolean $override = false)

Generate the charset query part

static string
getButtonOrImage(string $button_name, string $button_class, string $text, string $image, string $value = '')

Generate a button or image tag

static string
pageselector(string $name, int $rows, int $pageNow = 1, int $nbTotalPage = 1, int $showAll = 200, int $sliceStart = 5, int $sliceEnd = 5, int $percent = 20, int $range = 10, string $prompt = '')

Generate a pagination selector for browsing resultsets

static int
getPageFromPosition(int $pos, int $max_count)

Calculate page number through position

static string
getListNavigator(int $count, int $pos, array $_url_params, string $script, string $frame, int $max_count, string $name = 'pos', string[] $classes = [])

Prepare navigation for a list

static string
userDir(string $dir)

replaces %u in given path with current user name

static string
getDbLink(string $database = '')

returns html code for db link to default db page

static String
getExternalBug(string $functionality, string $component, string $minimum_version, string $bugref)

Prepare a lightbulb hint explaining a known external bug that affects a functionality

static string
getRadioFields(string $html_field_name, array $choices, string $checked_choice = '', boolean $line_break = true, boolean $escape_label = true, string $class = '', string $id_prefix = '')

Generates a set of radio HTML fields

static string
getDropdown(string $select_name, array $choices, string $active_choice, string $id, string $class = '', string $placeholder = null)

Generates and returns an HTML dropdown

static string
getDivForSliderEffect(string $id = '', string $message = '', string|null $overrideDefault = null)

Generates a slider effect (jQjuery) Takes care of generating the initial

and the link controlling the slider; you have to generate the

yourself after the sliding section.

static string
toggleButton(string $action, string $select_name, array $options, string $callback)

Creates an AJAX sliding toggle button (or and equivalent form when AJAX is disabled)

static void
clearUserCache()

Clears cache content which needs to be refreshed on user change.

static string
cacheKey()

Calculates session cache key

static boolean
cacheExists(string $var)

Verifies if something is cached in the session

static mixed
cacheGet(string $var, Closure $callback = null)

Gets cached information from the session

static void
cacheSet(string $var, mixed $val = null)

Caches information in the session

static void
cacheUnset(string $var)

Removes cached information from the session

static string
printableBitValue(int $value, int $length)

Converts a bit value to printable format; in MySQL a BIT field can be from 1 to 64 bits so we need this function because in PHP, decbin() supports only 32 bits on 32-bit servers

static string
convertBitDefaultValue(string $bit_default_value)

Converts a BIT type default value for example, b'010' becomes 010

static array
extractColumnSpec(string $columnspec)

Extracts the various parts from a column spec

static boolean
isForeignKeySupported(string $engine)

Verifies if this table's engine supports foreign keys

static bool
isForeignKeyCheck()

Is Foreign key check enabled?

static string
getFKCheckbox()

Get HTML for Foreign key check checkbox

static bool
handleDisableFKCheckInit()

Handle foreign key check request

static void
handleDisableFKCheckCleanup(bool $default_fk_check_value)

Cleanup changes done for foreign key check

static string
asWKT(string $data, bool $includeSRID = false)

Converts GIS data to Well Known Text format

static string
duplicateFirstNewline(string $string)

If the string starts with a \r\n pair (0x0d0a) add an extra \n

static string|bool
getTitleForTarget(string $target)

Get the action word corresponding to a script name in order to display it as a title in navigation panel

static string
getScriptNameForOption(string $target, string $location)

Get the script name corresponding to a plain English config word in order to append in links on navigation and main panel

static string
expandUserString(string $string, array|string $escape = null, array $updates = [])

Formats user string, expanding @VARIABLES@, accepting strftime format string.

static String
getBrowseUploadFileBlock(string $max_upload_size)

Prepare the form used to browse anywhere on the local server for a file to import

static String
getSelectUploadFileBlock(ImportPlugin[] $import_list, string $uploaddir)

Prepare the form used to select a file to import from the server upload directory

static array
buildActionTitles()

Build titles and icons for action links

static mixed
getSupportedDatatypes(bool $html = false, string $selected = '')

This function processes the datatypes supported by the DB, as specified in Types->getColumns() and either returns an array (useful for quickly checking if a datatype is supported) or an HTML snippet that creates a drop-down list.

static array
unsupportedDatatypes()

Returns a list of datatypes that are not (yet) handled by PMA.

static string[]
getGISDatatypes(bool $upper_case = false)

Return GIS data types

static string
createGISData(string $gis_string, int $mysqlVersion)

Generates GIS data based on the string passed.

static array
getGISFunctions(string $geom_type = null, bool $binary = true, bool $display = false)

Returns the names and details of the functions that can be applied on geometry data types.

static string
getDefaultFunctionForField(array $field, bool $insert_mode)

Returns default function for a particular column.

static string
getFunctionsForField(array $field, bool $insert_mode, array $foreignData)

Creates a dropdown box with MySQL functions for a particular column.

static bool
currentUserHasPrivilege(string $priv, mixed $db = null, mixed $tbl = null)

Checks if the current user has a specific privilege and returns true if the user indeed has that privilege or false if (s)he doesn't. This function must only be used for features that are available since MySQL 5, because it relies on the INFORMATION_SCHEMA database to be present.

static string
getServerType()

Returns server type for current connection

static string
getServerSSL()

Returns information about SSL status for current connection

static array
parseEnumSetValues(string $definition, bool $escapeHtml = true)

Parses ENUM/SET values

static String
getFirstOccurringRegularExpression(array $regex_array, String $query)

Get regular expression which occur first inside the given sql query.

static array|null
getMenuTabList(string $level = null)

Return the list of tabs for the menu with corresponding names

static string
addMicroseconds(string $value)

Add fractional seconds to time, datetime and timestamp strings.

static string
getCompressionMimeType(resource $file)

Reads the file, detects the compression MIME type, closes the file and returns the MIME type

static string
getNavigationLink(string $link, bool $showText, string $text, bool $showIcon, string $icon, string $linkId = '', boolean $disableAjax = false, string $linkTarget = '', array $classes = [])

Renders a single link for the top of the navigation panel

static string
getCollateForIS()

Provide COLLATE clause, if required, to perform case sensitive comparisons for queries on information_schema.

static array
processIndexData(array $indexes)

Process the index data.

static string
getStartAndNumberOfRowsPanel(string $sql_query)

Function to get html for the start row and number of rows panel

static bool
isVirtualColumnsSupported()

Returns whether the database server supports virtual columns

static array
getDbInfo(string $db, string|null $sub_part)

Gets the list of tables in the current db and information about these tables if possible

static array
getTablesWhenOpen(string $db, object $db_info_result)

Gets the list of tables in the current db, taking into account that they might be "in use"

static array
listPHPExtensions()

Returs list of used PHP extensions.

static string
requestString(mixed $value)

Converts given (request) paramter to string

static string
generateRandom(int $length, bool $asHex = false)

Generates random string consisting of ASCII chars

static string
date(string $format)

Wraper around PHP date function

static void
setTimeLimit()

Wrapper around php's set_time_limit

static mixed
getValueByKey(array $array, string|array $path, mixed $default = null)

Access to a multidimensional array by dot notation

static string
sortableTableHeader(string $title, string $sort, string $initialSortOrder = 'ASC')

Creates a clickable column header for table information

Details

at line 37
static boolean showIcons(string $value)

Checks whether configuration value tells to show icons.

Parameters

string $value Configuration option name

Return Value

boolean Whether to show icons.

at line 49
static boolean showText(string $value)

Checks whether configuration value tells to show text.

Parameters

string $value Configuration option name

Return Value

boolean Whether to show text.

at line 68
static string getIcon(string $icon, string $alternate = '', boolean $force_text = false, boolean $menu_icon = false, string $control_param = 'ActionLinksMode')

Returns an HTML IMG tag for a particular icon from a theme, which may be an actual file or an icon from a sprite.

This function takes into account the ActionLinksMode configuration setting and wraps the image tag in a span tag.

Parameters

string $icon name of icon file
string $alternate alternate text
boolean $force_text whether to force alternate text to be displayed
boolean $menu_icon whether this icon is for the menu bar or not
string $control_param which directive controls the display

Return Value

string an html snippet

at line 113
static string getImage(string $image, string $alternate = '', array $attributes = [])

Returns an HTML IMG tag for a particular image from a theme

The image name should match CSS class defined in icons.css.php

Parameters

string $image The name of the file to get
string $alternate Used to set 'alt' and 'title' attributes of the image
array $attributes An associative array of other attributes

Return Value

string an html IMG tag

at line 159
static string getFormattedMaximumUploadSize(integer $max_upload_size)

Returns the formatted maximum size for an upload

Parameters

integer $max_upload_size the size

Return Value

string the message

at line 177
static string generateHiddenMaxFileSize(integer $max_size)

Generates a hidden field which should indicate to the browser the maximum size for upload

Parameters

integer $max_size the size

Return Value

string the INPUT field

at line 194
static string escapeMysqlWildcards(string $name)

Add slashes before "_" and "%" characters for using them in MySQL database, table and field names.

Note: This function does not escape backslashes!

Parameters

string $name the string to escape

Return Value

string the escaped string

at line 209
static string unescapeMysqlWildcards(string $name)

removes slashes before "_" and "%" characters Note: This function does not unescape backslashes!

Parameters

string $name the string to escape

Return Value

string the escaped string

at line 224
static string unQuote(string $quoted_string, string $quote = null)

removes quotes (',",`) from a quoted string

checks if the string is quoted and removes this quotes

Parameters

string $quoted_string string to remove quotes from
string $quote type of quote to remove

Return Value

string unqoted string

at line 267
static string formatSql(string $sqlQuery, boolean $truncate = false)

format sql strings

Parameters

string $sqlQuery raw SQL string
boolean $truncate truncate the query if it is too long

Return Value

string the formatted sql

at line 294
static string showCopyToClipboard(string $text)

Displays a button to copy content to clipboard

Parameters

string $text Text to copy to clipboard

Return Value

string the html link

Displays a link to the documentation as an icon

Parameters

string $link documentation link
string $target optional link target
boolean $bbcode optional flag indicating whether to output bbcode

Return Value

string the html link

at line 333
static string getMySQLDocuURL(string $link, string $anchor = '')

Get a URL link to the official MySQL documentation

Parameters

string $link contains name of page/anchor that is being linked
string $anchor anchor to page part

Return Value

string the URL link

at line 370
static string linkToVarDocumentation(string $name, bool $useMariaDB = false, string $text = null)

Get a link to variable documentation

Parameters

string $name The variable name
bool $useMariaDB Use only MariaDB documentation
string $text (optional) The text for the link

Return Value

string link or empty string

at line 407
static string showMySQLDocu(string $link, bool $bigIcon = false, string|null $url = null, string|null $text = null, string $anchor = '')

Displays a link to the official MySQL documentation

Parameters

string $link contains name of page/anchor that is being linked
bool $bigIcon whether to use big icon (like in left frame)
string|null $url href attribute
string|null $text text of link
string $anchor anchor to page part

Return Value

string the html link

Returns link to documentation.

Parameters

string $page Page in documentation
string $anchor Optional anchor in page

Return Value

string URL

at line 471
static string showDocu(string $page, string $anchor = '', boolean $bbcode = false)

Displays a link to the phpMyAdmin documentation

Parameters

string $page Page in documentation
string $anchor Optional anchor in page
boolean $bbcode Optional flag indicating whether to output bbcode

Return Value

string the html link

at line 485
static string showPHPDocu(string $target)

Displays a link to the PHP documentation

Parameters

string $target anchor in documentation

Return Value

string the html link

at line 501
static string showHint(string $message)

Returns HTML code for a tooltip

Parameters

string $message the message for the tooltip

Return Value

string

at line 533
static string mysqlDie(string|bool $server_msg = '', string $sql_query = '', bool $is_modify_link = true, string $back_url = '', bool $exit = true)

Displays a MySQL error message in the main panel when $exit is true.

Returns the error message otherwise.

Parameters

string|bool $server_msg Server's error message.
string $sql_query The SQL query that failed.
bool $is_modify_link Whether to show a "modify" link or not.
string $back_url URL for the "back" link (full path is not required).
bool $exit Whether execution should be stopped or the error message should be returned.

Return Value

string

at line 762
static array getTableList(string $db, string $tables = null, integer $limit_offset = 0, int|bool $limit_count = false)

returns array with tables of given db with extended information and grouped

Parameters

string $db name of db
string $tables name of tables
integer $limit_offset list offset
int|bool $limit_count max tables to return

Return Value

array (recursive) grouped table list

at line 873
static mixed backquote(mixed $a_name, boolean $do_it = true)

Adds backquotes on both sides of a database, table or field name.

and escapes backquotes inside the name with another backquote

example: echo backquote('owners db'); //owner``s db`

Parameters

mixed $a_name the database, table or field name to "backquote" or array of it
boolean $do_it a flag to bypass this function (used by dump functions)

Return Value

mixed the "backquoted" database, table or field name

at line 918
static mixed backquoteCompat(mixed $a_name, string $compatibility = 'MSSQL', boolean $do_it = true)

Adds backquotes on both sides of a database, table or field name.

in compatibility mode

example: echo backquoteCompat('owners db'); //owner``s db`

Parameters

mixed $a_name the database, table or field name to "backquote" or array of it
string $compatibility string compatibility mode (used by dump functions)
boolean $do_it a flag to bypass this function (used by dump functions)

Return Value

mixed the "backquoted" database, table or field name

at line 966
static string getMessage(Message|string $message, string $sql_query = null, string $type = 'notice')

Prepare the message and the query usually the message is the result of the query executed

Parameters

Message|string $message the message to display
string $sql_query the query to display
string $type the type (level) of the message

Return Value

string

at line 1268
static boolean profilingSupported()

Verifies if current MySQL server supports profiling

Return Value

boolean whether profiling is supported

at line 1296
static array|null formatByteDown(double|int $value, int $limes = 6, int $comma = 0)

Formats $value to byte view

Parameters

double|int $value the value to format
int $limes the sensitiveness
int $comma the number of decimals to retain

Return Value

array|null the formatted value and its unit

at line 1376
static string formatNumber(double $value, integer $digits_left = 3, integer $digits_right = 0, boolean $only_down = false, boolean $noTrailingZero = true)

Formats $value to the given length and appends SI prefixes with a $length of 0 no truncation occurs, number is only formatted to the current locale

examples: echo formatNumber(123456789, 6); // 123,457 k echo formatNumber(-123456789, 4, 2); // -123.46 M echo formatNumber(-0.003, 6); // -3 m echo formatNumber(0.003, 3, 3); // 0.003 echo formatNumber(0.00003, 3, 2); // 0.03 m echo formatNumber(0, 6); // 0

Parameters

double $value the value to format
integer $digits_left number of digits left of the comma
integer $digits_right number of digits right of the comma
boolean $only_down do not reformat numbers below 1
boolean $noTrailingZero removes trailing zeros right of the comma (default: true)

Return Value

string the formatted value and its unit

at line 1493
static integer extractValueFromFormattedSize(string $formatted_size)

Returns the number of bytes when a formatted size is given

Parameters

string $formatted_size the size expression (for example 8MB)

Return Value

integer The numerical part of the expression (for example 8)

at line 1531
static string localisedDate(integer $timestamp = -1, string $format = '')

Writes localised date

Parameters

integer $timestamp the current timestamp
string $format format

Return Value

string the formatted date

at line 1626
static string getHtmlTab(array $tab, array $url_params = [])

returns a tab for tabbed navigation.

If the variables $link and $args ar left empty, an inactive tab is created

Parameters

array $tab array with all options
array $url_params tab specific URL parameters

Return Value

string html code for one tab, a link if valid otherwise a span

at line 1730
static string getHtmlTabs(array $tabs, array $url_params, string $menu_id, bool $resizable = false)

returns html-code for a tab navigation

Parameters

array $tabs one element per tab
array $url_params additional URL parameters
string $menu_id HTML id attribute for the menu container
bool $resizable whether to add a "resizable" class

Return Value

string html-code for tab-navigation

at line 1777
static string linkOrButton(string $url, string $message, mixed $tag_params = [], string $target = '')

Displays a link, or a link with code to trigger POST request.

POST is used in following cases:

  • URL is too long
  • URL components are over Suhosin limits
  • There is SQL query in the parameters

Parameters

string $url the URL
string $message the link message
mixed $tag_params string: js confirmation; array: additional tag params (f.e. style="")
string $target target

Return Value

string the results to be echoed or saved in an array

at line 1860
static array splitURLQuery(string $url)

Splits a URL string by parameter

Parameters

string $url the URL

Return Value

array the parameter/value pairs, for example [0] db=sakila

at line 1889
static string timespanFormat(int $seconds)

Returns a given timespan value in a readable format.

Parameters

int $seconds the timespan

Return Value

string the formatted value

at line 1928
static void checkParameters(string[] $params, boolean $request = false)

Function added to avoid path disclosures.

Called by each script that needs parameters, it displays an error message and, by default, stops the execution.

Parameters

string[] $params The names of the parameters needed by the calling script
boolean $request Check parameters in request

Return Value

void

at line 1972
static array getUniqueCondition(resource $handle, integer $fields_cnt, array $fields_meta, array $row, boolean $force_unique = false, string|boolean $restrict_to_table = false, array|null $analyzed_sql_results = null)

Function to generate unique condition for specified row.

Parameters

resource $handle current query result
integer $fields_cnt number of fields
array $fields_meta meta information about fields
array $row current row
boolean $force_unique generate condition only on pk or unique
string|boolean $restrict_to_table restrict the unique condition to this table or false if none
array|null $analyzed_sql_results the analyzed query

Return Value

array the calculated condition and whether condition is unique

at line 2147
static string getCharsetQueryPart(string $collation, boolean $override = false)

Generate the charset query part

Parameters

string $collation Collation
boolean $override (optional) force 'CHARACTER SET' keyword

Return Value

string

at line 2172
static string getButtonOrImage(string $button_name, string $button_class, string $text, string $image, string $value = '')

Generate a button or image tag

Parameters

string $button_name name of button element
string $button_class class of button or image element
string $text text to display
string $image image to display
string $value value

Return Value

string html content

at line 2216
static string pageselector(string $name, int $rows, int $pageNow = 1, int $nbTotalPage = 1, int $showAll = 200, int $sliceStart = 5, int $sliceEnd = 5, int $percent = 20, int $range = 10, string $prompt = '')

Generate a pagination selector for browsing resultsets

Parameters

string $name The name for the request parameter
int $rows Number of rows in the pagination set
int $pageNow current page number
int $nbTotalPage number of total pages
int $showAll If the number of pages is lower than this variable, no pages will be omitted in pagination
int $sliceStart How many rows at the beginning should always be shown?
int $sliceEnd How many rows at the end should always be shown?
int $percent Percentage of calculation page offsets to hop to a next page
int $range Near the current page, how many pages should be considered "nearby" and displayed as well?
string $prompt The prompt to display (sometimes empty)

Return Value

string

at line 2345
static int getPageFromPosition(int $pos, int $max_count)

Calculate page number through position

Parameters

int $pos position of first item
int $max_count number of items per page

Return Value

int $page_num

at line 2369
static string getListNavigator(int $count, int $pos, array $_url_params, string $script, string $frame, int $max_count, string $name = 'pos', string[] $classes = [])

Prepare navigation for a list

Parameters

int $count number of elements in the list
int $pos current position in the list
array $_url_params url parameters
string $script script name for form target
string $frame target frame
int $max_count maximum number of elements to display from the list
string $name the name for the request parameter
string[] $classes additional classes for the container

Return Value

string the html content

at line 2484
static string userDir(string $dir)

replaces %u in given path with current user name

example: $user_dir = userDir('/var/pma_tmp/%u/'); // '/var/pma_tmp/root/'

Parameters

string $dir with wildcard for user

Return Value

string per user directory

returns html code for db link to default db page

Parameters

string $database database

Return Value

string html link to default db page

at line 2540
static String getExternalBug(string $functionality, string $component, string $minimum_version, string $bugref)

Prepare a lightbulb hint explaining a known external bug that affects a functionality

Parameters

string $functionality localized message explaining the func.
string $component 'mysql' (eventually, 'php')
string $minimum_version of this component
string $bugref bug reference for this component

Return Value

String

at line 2573
static string getRadioFields(string $html_field_name, array $choices, string $checked_choice = '', boolean $line_break = true, boolean $escape_label = true, string $class = '', string $id_prefix = '')

Generates a set of radio HTML fields

Parameters

string $html_field_name the radio HTML field
array $choices the choices values and labels
string $checked_choice the choice to check by default
boolean $line_break whether to add HTML line break after a choice
boolean $escape_label whether to use htmlspecialchars() on label
string $class enclose each choice with a div of this class
string $id_prefix prefix for the id attribute, name will be used if this is not supplied

Return Value

string set of html radio fiels

at line 2628
static string getDropdown(string $select_name, array $choices, string $active_choice, string $id, string $class = '', string $placeholder = null)

Generates and returns an HTML dropdown

Parameters

string $select_name name for the select element
array $choices choices values
string $active_choice the choice to select by default
string $id id of the select element; can be different in case the dropdown is present more than once on the page
string $class class for the select element
string $placeholder Placeholder for dropdown if nothing else is selected

Return Value

string html content

at line 2673
static string getDivForSliderEffect(string $id = '', string $message = '', string|null $overrideDefault = null)

Generates a slider effect (jQjuery) Takes care of generating the initial

and the link controlling the slider; you have to generate the

yourself after the sliding section.

Parameters

string $id the id of the

<

div> on which to apply the effect

string $message the message to show as a link
string|null $overrideDefault override InitialSlidersState config

Return Value

string html div element

at line 2695
static string toggleButton(string $action, string $select_name, array $options, string $callback)

Creates an AJAX sliding toggle button (or and equivalent form when AJAX is disabled)

Parameters

string $action The URL for the request to be executed
string $select_name The name for the dropdown box
array $options An array of options (see PhpMyAdmin\Rte\Footer)
string $callback A JS snippet to execute when the request is successfully processed

Return Value

string HTML code for the toggle button

at line 2728
static void clearUserCache()

Clears cache content which needs to be refreshed on user change.

Return Value

void

at line 2740
static string cacheKey()

Calculates session cache key

Return Value

string

at line 2756
static boolean cacheExists(string $var)

Verifies if something is cached in the session

Parameters

string $var variable name

Return Value

boolean

at line 2769
static mixed cacheGet(string $var, Closure $callback = null)

Gets cached information from the session

Parameters

string $var variable name
Closure $callback callback to fetch the value

Return Value

mixed

at line 2791
static void cacheSet(string $var, mixed $val = null)

Caches information in the session

Parameters

string $var variable name
mixed $val value

Return Value

void

at line 2803
static void cacheUnset(string $var)

Removes cached information from the session

Parameters

string $var variable name

Return Value

void

at line 2819
static string printableBitValue(int $value, int $length)

Converts a bit value to printable format; in MySQL a BIT field can be from 1 to 64 bits so we need this function because in PHP, decbin() supports only 32 bits on 32-bit servers

Parameters

int $value coming from a BIT field
int $length length

Return Value

string the printable value

at line 2858
static string convertBitDefaultValue(string $bit_default_value)

Converts a BIT type default value for example, b'010' becomes 010

Parameters

string $bit_default_value value

Return Value

string the converted value

at line 2871
static array extractColumnSpec(string $columnspec)

Extracts the various parts from a column spec

Parameters

string $columnspec Column specification

Return Value

array associative array containing type, spec_in_brackets and possibly enum_set_values (another array)

at line 2996
static boolean isForeignKeySupported(string $engine)

Verifies if this table's engine supports foreign keys

Parameters

string $engine engine

Return Value

boolean

at line 3019
static bool isForeignKeyCheck()

Is Foreign key check enabled?

Return Value

bool

at line 3034
static string getFKCheckbox()

Get HTML for Foreign key check checkbox

Return Value

string HTML for checkbox

at line 3047
static bool handleDisableFKCheckInit()

Handle foreign key check request

Return Value

bool Default foreign key checks value

at line 3070
static void handleDisableFKCheckCleanup(bool $default_fk_check_value)

Cleanup changes done for foreign key check

Parameters

bool $default_fk_check_value original value for 'FOREIGN_KEY_CHECKS'

Return Value

void

at line 3086
static string asWKT(string $data, bool $includeSRID = false)

Converts GIS data to Well Known Text format

Parameters

string $data GIS data
bool $includeSRID Add SRID to the WKT

Return Value

string GIS data in Well Know Text format

at line 3123
static string duplicateFirstNewline(string $string)

If the string starts with a \r\n pair (0x0d0a) add an extra \n

Parameters

string $string string

Return Value

string with the chars replaced

at line 3142
static string|bool getTitleForTarget(string $target)

Get the action word corresponding to a script name in order to display it as a title in navigation panel

Parameters

string $target a valid value for $cfg['NavigationTreeDefaultTabTable'], $cfg['NavigationTreeDefaultTabTable2'], $cfg['DefaultTabTable'] or $cfg['DefaultTabDatabase']

Return Value

string|bool Title for the $cfg value

at line 3168
static string getScriptNameForOption(string $target, string $location)

Get the script name corresponding to a plain English config word in order to append in links on navigation and main panel

Parameters

string $target a valid value for $cfg['NavigationTreeDefaultTabTable'], $cfg['NavigationTreeDefaultTabTable2'], $cfg['DefaultTabTable'], $cfg['DefaultTabDatabase'] or $cfg['DefaultTabServer']
string $location one out of 'server', 'table', 'database'

Return Value

string script name corresponding to the config word

at line 3232
static string expandUserString(string $string, array|string $escape = null, array $updates = [])

Formats user string, expanding @VARIABLES@, accepting strftime format string.

Parameters

string $string Text where to do expansion.
array|string $escape Function to call for escaping variable values. Can also be an array of: - the escape method name - the class that contains the method - location of the class (for inclusion)
array $updates Array with overrides for default parameters (obtained from GLOBALS).

Return Value

string

at line 3333
static String getBrowseUploadFileBlock(string $max_upload_size)

Prepare the form used to browse anywhere on the local server for a file to import

Parameters

string $max_upload_size maximum upload size

Return Value

String

at line 3363
static String getSelectUploadFileBlock(ImportPlugin[] $import_list, string $uploaddir)

Prepare the form used to select a file to import from the server upload directory

Parameters

ImportPlugin[] $import_list array of import plugins
string $uploaddir upload directory

Return Value

String

at line 3420
static array buildActionTitles()

Build titles and icons for action links

Return Value

array the action titles

at line 3460
static mixed getSupportedDatatypes(bool $html = false, string $selected = '')

This function processes the datatypes supported by the DB, as specified in Types->getColumns() and either returns an array (useful for quickly checking if a datatype is supported) or an HTML snippet that creates a drop-down list.

Parameters

bool $html Whether to generate an html snippet or an array
string $selected The value to mark as selected in HTML mode

Return Value

mixed An HTML snippet or an array of datatypes.

at line 3531
static array unsupportedDatatypes()

Returns a list of datatypes that are not (yet) handled by PMA.

Used by: /table/change and libraries/db_routines.inc.php

Return Value

array list of datatypes

at line 3543
static string[] getGISDatatypes(bool $upper_case = false)

Return GIS data types

Parameters

bool $upper_case whether to return values in upper case

Return Value

string[] GIS data types

at line 3569
static string createGISData(string $gis_string, int $mysqlVersion)

Generates GIS data based on the string passed.

Parameters

string $gis_string GIS string
int $mysqlVersion The mysql version as int

Return Value

string GIS data enclosed in 'ST_GeomFromText' or 'GeomFromText' function

at line 3598
static array getGISFunctions(string $geom_type = null, bool $binary = true, bool $display = false)

Returns the names and details of the functions that can be applied on geometry data types.

Parameters

string $geom_type if provided the output is limited to the functions that are applicable to the provided geometry type.
bool $binary if set to false functions that take two geometries as arguments will not be included.
bool $display if set to true separators will be added to the output array.

Return Value

array names and details of the functions that can be applied on geometry data types.

at line 3837
static string getDefaultFunctionForField(array $field, bool $insert_mode)

Returns default function for a particular column.

Parameters

array $field Data about the column for which to generate the dropdown
bool $insert_mode Whether the operation is 'insert'

Return Value

string An HTML snippet of a dropdown list with function names appropriate for the requested column.

at line 3896
static string getFunctionsForField(array $field, bool $insert_mode, array $foreignData)

Creates a dropdown box with MySQL functions for a particular column.

Parameters

array $field Data about the column for which to generate the dropdown
bool $insert_mode Whether the operation is 'insert'
array $foreignData Foreign data

Return Value

string An HTML snippet of a dropdown list with function names appropriate for the requested column.

at line 3959
static bool currentUserHasPrivilege(string $priv, mixed $db = null, mixed $tbl = null)

Checks if the current user has a specific privilege and returns true if the user indeed has that privilege or false if (s)he doesn't. This function must only be used for features that are available since MySQL 5, because it relies on the INFORMATION_SCHEMA database to be present.

Example: currentUserHasPrivilege('CREATE ROUTINE', 'mydb'); // Checks if the currently logged in user has the global // 'CREATE ROUTINE' privilege or, if not, checks if the // user has this privilege on database 'mydb'.

Parameters

string $priv The privilege to check
mixed $db null, to only check global privileges string, db name where to also check for privileges
mixed $tbl null, to only check global/db privileges string, table name where to also check for privileges

Return Value

bool

at line 4044
static string getServerType()

Returns server type for current connection

Known types are: MariaDB, Percona and MySQL (default)

Return Value

string

at line 4062
static string getServerSSL()

Returns information about SSL status for current connection

Return Value

string

at line 4091
static array parseEnumSetValues(string $definition, bool $escapeHtml = true)

Parses ENUM/SET values

Parameters

string $definition The definition of the column for which to parse the values
bool $escapeHtml Whether to escape html entities

Return Value

array

at line 4148
static String getFirstOccurringRegularExpression(array $regex_array, String $query)

Get regular expression which occur first inside the given sql query.

Parameters

array $regex_array Comparing regular expressions.
String $query SQL query to be checked.

Return Value

String Matching regular expression.

at line 4173
static array|null getMenuTabList(string $level = null)

Return the list of tabs for the menu with corresponding names

Parameters

string $level 'server', 'db' or 'table' level

Return Value

array|null list of tabs for the menu

at line 4240
static string addMicroseconds(string $value)

Add fractional seconds to time, datetime and timestamp strings.

If the string contains fractional seconds, pads it with 0s up to 6 decimal places.

Parameters

string $value time, datetime or timestamp strings

Return Value

string time, datetime or timestamp strings with fractional seconds

at line 4267
static string getCompressionMimeType(resource $file)

Reads the file, detects the compression MIME type, closes the file and returns the MIME type

Parameters

resource $file the file handle

Return Value

string the MIME type for compression, or 'none'

Renders a single link for the top of the navigation panel

Parameters

string $link The url for the link
bool $showText Whether to show the text or to only use it for title attributes
string $text The text to display and use for title attributes
bool $showIcon Whether to show the icon
string $icon The filename of the icon to show
string $linkId Value to use for the ID attribute
boolean $disableAjax Whether to disable ajax page loading for this link
string $linkTarget The name of the target frame for the link
array $classes HTML classes to apply

Return Value

string HTML code for one link

at line 4347
static string getCollateForIS()

Provide COLLATE clause, if required, to perform case sensitive comparisons for queries on information_schema.

Return Value

string COLLATE clause if needed or empty string.

at line 4365
static array processIndexData(array $indexes)

Process the index data.

Parameters

array $indexes index data

Return Value

array processes index data

at line 4419
static string getStartAndNumberOfRowsPanel(string $sql_query)

Function to get html for the start row and number of rows panel

Parameters

string $sql_query sql query

Return Value

string html

at line 4457
static bool isVirtualColumnsSupported()

Returns whether the database server supports virtual columns

Return Value

bool

at line 4475
static array getDbInfo(string $db, string|null $sub_part)

Gets the list of tables in the current db and information about these tables if possible

Parameters

string $db database name
string|null $sub_part part of script name

Return Value

array

at line 4651
static array getTablesWhenOpen(string $db, object $db_info_result)

Gets the list of tables in the current db, taking into account that they might be "in use"

Parameters

string $db database name
object $db_info_result result set

Return Value

array list of tables

at line 4731
static array listPHPExtensions()

Returs list of used PHP extensions.

Return Value

array of strings

at line 4758
static string requestString(mixed $value)

Converts given (request) paramter to string

Parameters

mixed $value Value to convert

Return Value

string

at line 4774
static string generateRandom(int $length, bool $asHex = false)

Generates random string consisting of ASCII chars

Parameters

int $length Length of string
bool $asHex (optional) Send the result as hex

Return Value

string

at line 4804
static string date(string $format)

Wraper around PHP date function

Parameters

string $format Date format string

Return Value

string

at line 4817
static void setTimeLimit()

Wrapper around php's set_time_limit

Return Value

void

at line 4834
static mixed getValueByKey(array $array, string|array $path, mixed $default = null)

Access to a multidimensional array by dot notation

Parameters

array $array List of values
string|array $path Path to searched value
mixed $default Default value

Return Value

mixed Searched value

at line 4860
static string sortableTableHeader(string $title, string $sort, string $initialSortOrder = 'ASC')

Creates a clickable column header for table information

Parameters

string $title Title to use for the link
string $sort Corresponds to sortable data name mapped in Util::getDbInfo
string $initialSortOrder Initial sort order

Return Value

string Link to be displayed in the table header