WP_CLI\Utils
get_mysql_version()
Get the version of the MySQL or MariaDB database.
No Hooks.
Returns
String. Version of the MySQL/MariaDB database, or an empty string if not found.
Usage
get_mysql_version();
Changelog
| Since 2.12.0 | Introduced. |
| Since 2.12.0 | Now also checks for MariaDB. |
get_mysql_version() get mysql version code WP-CLI 2.13.0-alpha
function get_mysql_version() {
static $version = null;
if ( null !== $version ) {
return $version;
}
$db_type = get_db_type();
if ( 'sqlite' !== $db_type ) {
$result = Process::create( "/usr/bin/env $db_type --version", null, null )->run();
if ( 0 !== $result->return_code ) {
$version = '';
} else {
$version = trim( $result->stdout );
}
}
return $version;
}