WP_CLI\Utils

get_sql_modes()WP-CLI 1.0

Get the SQL modes of the MySQL session.

No Hooks.

Returns

String[]. Array of SQL modes, or an empty array if they couldn't be read.

Usage

get_sql_modes();

get_sql_modes() code WP-CLI 2.13.0-alpha

function get_sql_modes() {
	static $sql_modes = null;

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

	$binary = get_mysql_binary_path();

	if ( '' === $binary ) {
		$sql_modes = [];
	} else {
		$result = Process::create( "$binary --no-auto-rehash --batch --skip-column-names --execute=\"SELECT @@SESSION.sql_mode\"", null, null )->run();

		if ( 0 !== $result->return_code ) {
			$sql_modes = [];
		} else {
			$sql_modes = array_filter(
				array_map(
					'trim',
					preg_split( "/\r\n|\n|\r/", $result->stdout )
				)
			);
		}
	}

	return $sql_modes;
}