wpdb::set_sql_mode()publicWP 3.9.0

Changes the current SQL mode, and ensures its WordPress compatibility.

If no modes are passed, it will ensure the current MySQL server modes are compatible.

Метод класса: wpdb{}

Хуки из метода

Возвращает

null. Ничего (null).

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

global $wpdb;
$wpdb->set_sql_mode( $modes );
$modes(массив)
A list of SQL modes to set.
По умолчанию: empty array

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

С версии 3.9.0 Введена.

Код wpdb::set_sql_mode() WP 6.4.3

public function set_sql_mode( $modes = array() ) {
	if ( empty( $modes ) ) {
		$res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' );

		if ( empty( $res ) ) {
			return;
		}

		$modes_array = mysqli_fetch_array( $res );

		if ( empty( $modes_array[0] ) ) {
			return;
		}

		$modes_str = $modes_array[0];

		if ( empty( $modes_str ) ) {
			return;
		}

		$modes = explode( ',', $modes_str );
	}

	$modes = array_change_key_case( $modes, CASE_UPPER );

	/**
	 * Filters the list of incompatible SQL modes to exclude.
	 *
	 * @since 3.9.0
	 *
	 * @param array $incompatible_modes An array of incompatible modes.
	 */
	$incompatible_modes = (array) apply_filters( 'incompatible_sql_modes', $this->incompatible_modes );

	foreach ( $modes as $i => $mode ) {
		if ( in_array( $mode, $incompatible_modes, true ) ) {
			unset( $modes[ $i ] );
		}
	}

	$modes_str = implode( ',', $modes );

	mysqli_query( $this->dbh, "SET SESSION sql_mode='$modes_str'" );
}