Util
class Util (View source)
Misc functions used all over the scripts.
Methods
Checks whether configuration value tells to show icons.
Checks whether configuration value tells to show text.
Returns the formatted maximum size for an upload
removes quotes (',",`) from a quoted string
Get a URL link to the official MySQL documentation
Get a URL link to the official documentation page of either MySQL or MariaDB depending on the database server of the user.
Adds backquotes on both sides of a database, table or field name.
Adds backquotes on both sides of a database, table or field name.
Formats $value to byte view
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
Returns the number of bytes when a formatted size is given
Splits a URL string by parameter
Returns a given timespan value in a readable format.
Generate the charset query part
Generate a pagination selector for browsing resultsets
Calculate page number through position
replaces %u in given path with current user name
Clears cache content which needs to be refreshed on user change.
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
Converts a BIT type default value for example, b'010' becomes 010
Extracts the various parts from a column spec
If the string starts with a \r\n pair (0x0d0a) add an extra \n
Get the action word corresponding to a script name in order to display it as a title in navigation panel
Get the script name corresponding to a plain English config word in order to append in links on navigation and main panel
Get the URL corresponding to a plain English config word in order to append in links on navigation and main panel
Formats user string, expanding @VARIABLES@, accepting strftime format string.
This function processes the datatypes supported by the DB, as specified in Types->getColumns() and returns an array (useful for quickly checking if a datatype is supported).
Returns a list of datatypes that are not (yet) handled by PMA.
This function is to check whether database support UUID
Checks if the current user has a specific privilege and returns true if the user indeed has that privilege or false if they don'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.
Returns server type for current connection
Parses ENUM/SET values
Return the list of tabs for the menu with corresponding names
Add fractional seconds to time, datetime and timestamp strings.
Reads the file, detects the compression MIME type, closes the file and returns the MIME type
Provide COLLATE clause, if required, to perform case sensitive comparisons for queries on information_schema.
Process the index data.
Gets the list of tables in the current db and information about these tables if possible.
Returns list of used PHP extensions.
Converts given (request) parameter to string
Generates random string consisting of ASCII chars
Wrapper around PHP date function
Wrapper around php's set_time_limit
Access to a multidimensional array recursively by the keys specified in $path
Creates a clickable column header for table information
Check that input is an int or an int in a string
Get the protocol from the RFC 7239 Forwarded header
Details
static bool
showIcons(string $value)
Checks whether configuration value tells to show icons.
static bool
showText(string $value)
Checks whether configuration value tells to show text.
static string
getFormattedMaximumUploadSize(int|float|string $maxUploadSize)
Returns the formatted maximum size for an upload
static string
unQuote(string $quotedString, string|null $quote = null)
removes quotes (',",`) from a quoted string
checks if the string is quoted and removes this quotes
static string
getMySQLDocuURL(string $link, string $anchor = '')
Get a URL link to the official MySQL documentation
static string
getDocuURL(bool $isMariaDB = false)
Get a URL link to the official documentation page of either MySQL or MariaDB depending on the database server of the user.
static string
backquote(Stringable|string|null $identifier)
Adds backquotes on both sides of a database, table or field name.
and escapes backquotes inside the name with another backquote
example:
echo backquote('owner`s db'); // `owner``s db`
static string
backquoteCompat(Stringable|string|null $identifier, string $compatibility = 'MSSQL', bool $doIt = true)
Adds backquotes on both sides of a database, table or field name.
in compatibility mode
example:
echo backquoteCompat('owner`s db'); // `owner``s db`
static array|null
formatByteDown(float|int|string|null $value, int $limes = 6, int $comma = 0)
Formats $value to byte view
static string
formatNumber(float|int|string $value, int $digitsLeft = 3, int $digitsRight = 0, bool $onlyDown = false, bool $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
static int|float
extractValueFromFormattedSize(string|int $formattedSize)
Returns the number of bytes when a formatted size is given
static string
localisedDate(DateTimeImmutable $dateTime, string $format = '')
Writes localised date
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 string
getCharsetQueryPart(string $collation, bool $override = false)
Generate the charset query part
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 $maxCount)
Calculate page number through position
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/'
static void
clearUserCache()
Clears cache content which needs to be refreshed on user change.
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|null $bitDefaultValue)
Converts a BIT type default value for example, b'010' becomes 010
static array
extractColumnSpec(string $columnSpecification)
Extracts the various parts from a column spec
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
getUrlForOption(string $target, string $location)
Get the URL corresponding to a plain English config word in order to append in links on navigation and main panel
static string
expandUserString(string $string, callable|null $escape = null, array $updates = [])
Formats user string, expanding @VARIABLES@, accepting strftime format string.
static array
getSupportedDatatypes()
This function processes the datatypes supported by the DB, as specified in Types->getColumns() and returns an array (useful for quickly checking if a datatype is supported).
static array
unsupportedDatatypes()
Returns a list of datatypes that are not (yet) handled by PMA.
Used by: /table/change and libraries/Routines.php
static bool
isUUIDSupported()
This function is to check whether database support UUID
static bool
currentUserHasPrivilege(string $priv, string|null $db = null, string|null $tbl = null)
Checks if the current user has a specific privilege and returns true if the user indeed has that privilege or false if they don'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'.
static string
getServerType()
Returns server type for current connection
Known types are: MariaDB, Percona Server and MySQL (default)
static array
parseEnumSetValues(string $definition, bool $escapeHtml = true)
Parses ENUM/SET values
static array
getMenuTabList(UserGroupLevel $level)
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.
If the string contains fractional seconds, pads it with 0s up to 6 decimal places.
static string
getCompressionMimeType(resource $file)
Reads the file, detects the compression MIME type, closes the file and returns the MIME type
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 array
getDbInfo(ServerRequest $request, string $db, bool $isResultLimited = true)
Gets the list of tables in the current db and information about these tables if possible.
static array
listPHPExtensions()
Returns list of used PHP extensions.
static string
requestString(mixed $value)
Converts given (request) parameter to string
static string
generateRandom(int $length, bool $asHex = false)
Generates random string consisting of ASCII chars
static string
date(string $format)
Wrapper around PHP date function
static void
setTimeLimit()
Wrapper around php's set_time_limit
static mixed
getValueByKey(array $array, array $path, mixed $default = null)
Access to a multidimensional array recursively by the keys specified in $path
static string
sortableTableHeader(string $title, string $sort, string $initialSortOrder = 'ASC')
Creates a clickable column header for table information
static bool
isInteger(mixed $input)
Check that input is an int or an int in a string
static string
getProtoFromForwardedHeader(string $headerContents)
Get the protocol from the RFC 7239 Forwarded header
static int
getTableListPosition(ServerRequest $request, string $db)
No description