WP_CLI\Utils

get_sql_modes()WP-CLI 1.0

Get the SQL modes of the MySQL session.

No Hooks.

Return

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.7.0-alpha

function get_sql_modes() {
	static $sql_modes = null;

	if ( null === $sql_modes ) {
		$result = Process::create( '/usr/bin/env mysql --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;
}