WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_CLI\Utils

run_mysql_command() WP-CLI 2.5.0

Run a MySQL command and optionally return the output.

Хуков нет.

Возвращает

Массив. Associative array containing STDOUT and STDERR output.

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

run_mysql_command( $cmd, $assoc_args, $_, $send_to_shell, $interactive );
$cmd(строка) (обязательный)
Command to run.
$assoc_args(массив) (обязательный)
Associative array of arguments to use.
$_(разное)
Deprecated. Former $descriptors argument.
По умолчанию: null
$send_to_shell(true|false)
Whether to send STDOUT and STDERR immediately to the shell.
По умолчанию: true
$interactive(true|false)
Whether MySQL is meant to be executed as an interactive process.
По умолчанию: false

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

С версии 2.5.0 Введена.
Since v2.5.0 Deprecated $descriptors argument.

Код run_mysql_command() WP-CLI 2.5.0

function run_mysql_command( $cmd, $assoc_args, $_ = null, $send_to_shell = true, $interactive = false ) {
	check_proc_available( 'run_mysql_command' );

	$descriptors = $interactive ?
		[
			0 => STDIN,
			1 => STDOUT,
			2 => STDERR,
		] :
		[
			0 => STDIN,
			1 => [ 'pipe', 'w' ],
			2 => [ 'pipe', 'w' ],
		];

	$stdout = '';
	$stderr = '';
	$pipes  = [];

	if ( isset( $assoc_args['host'] ) ) {
		// phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_host_to_cli_args -- Misidentified as PHP native MySQL function.
		$assoc_args = array_merge( $assoc_args, mysql_host_to_cli_args( $assoc_args['host'] ) );
	}

	if ( isset( $assoc_args['pass'] ) ) {
		$old_password = getenv( 'MYSQL_PWD' );
		putenv( 'MYSQL_PWD=' . $assoc_args['pass'] );
		unset( $assoc_args['pass'] );
	}

	$final_cmd = force_env_on_nix_systems( $cmd ) . assoc_args_to_str( $assoc_args );

	WP_CLI::debug( 'Final MySQL command: ' . $final_cmd, 'db' );
	$process = proc_open_compat( $final_cmd, $descriptors, $pipes );

	if ( isset( $old_password ) ) {
		putenv( 'MYSQL_PWD=' . $old_password );
	}

	if ( ! $process ) {
		exit( 1 );
	}

	if ( ! $interactive && is_resource( $process ) ) {
		$stdout = stream_get_contents( $pipes[1] );
		$stderr = stream_get_contents( $pipes[2] );

		fclose( $pipes[1] );
		fclose( $pipes[2] );
	}

	$exit_code = proc_close( $process );

	if ( $interactive && $exit_code ) {
		exit( $exit_code );
	}

	if ( $send_to_shell ) {
		fwrite( STDOUT, $stdout );
		fwrite( STDERR, $stderr );

		if ( $exit_code ) {
			exit( $exit_code );
		}
	}

	return [
		$stdout,
		$stderr,
		$exit_code,
	];
}