WP_CLI\Utils

get_db_type()WP-CLI 1.0

Return the detected database type.

Can be either 'sqlite' (if in a WordPress installation with the SQLite drop-in), 'mysql', or 'mariadb'.

No Hooks.

Returns

String. Database type.

Usage

get_db_type();

get_db_type() code WP-CLI 2.13.0-alpha

function get_db_type() {
	static $db_type = null;

	if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
		return 'sqlite';
	}

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

	$db_type = 'mysql';

	$binary = get_mysql_binary_path();

	if ( '' !== $binary ) {
		$result = Process::create( "$binary --version", null, null )->run();

		if ( 0 === $result->return_code ) {
			$db_type = ( false !== strpos( $result->stdout, 'MariaDB' ) ) ? 'mariadb' : 'mysql';
		}
	}

	return $db_type;
}