WP_CLI\Utils

get_mysql_binary_path()WP-CLI 2.12.0

Get the path to the MySQL or MariaDB binary.

If the MySQL binary is provided by MariaDB (as determined by the version string), prefers the actual MariaDB binary.

Хуков нет.

Возвращает

Строку. Path to the MySQL/MariaDB binary, or an empty string if not found.

Использование

get_mysql_binary_path();

Список изменений

С версии 2.12.0 Введена.
С версии 2.12.0 Now also checks for MariaDB.

Код get_mysql_binary_path() WP-CLI 2.13.0-alpha

function get_mysql_binary_path() {
	static $path = null;

	if ( null !== $path ) {
		return $path;
	}

	$path    = '';
	$mysql   = Process::create( '/usr/bin/env which mysql', null, null )->run();
	$mariadb = Process::create( '/usr/bin/env which mariadb', null, null )->run();

	$mysql_binary   = trim( $mysql->stdout );
	$mariadb_binary = trim( $mariadb->stdout );

	if ( 0 === $mysql->return_code ) {
		if ( '' !== $mysql_binary ) {
			$path   = $mysql_binary;
			$result = Process::create( "$mysql_binary --version", null, null )->run();

			// It's actually MariaDB disguised as MySQL.
			if ( 0 === $result->return_code && false !== strpos( $result->stdout, 'MariaDB' ) && 0 === $mariadb->return_code ) {
				$path = $mariadb_binary;
			}
		}
	} elseif ( 0 === $mariadb->return_code ) {
		$path = $mariadb_binary;
	}

	return $path;
}