# esc_sql()

URL: https://chugunov.pro/api-wordpress/functions/esc_sql/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.8.0.

## Сигнатура

```php
esc_sql( string|array $data ): string|array
```

## Описание

Usually you should prepare queries using [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/).
Sometimes, spot-escaping is required or useful. One example is preparing an array for use in an IN clause.

NOTE: Since 4.8.3, ‘%’ characters will be replaced with a placeholder string, this prevents certain SQLi attacks from taking place. This change in behavior may cause issues for code that expects the return value of [esc_sql()](https://developer.wordpress.org/reference/functions/esc_sql/) to be usable for other purposes.

## Параметры

- `$data` `string|array` — обязательный. Неэкранированные данные.

## Возвращаемое значение

`string|array`

## Исходный код

Файл: `wp-includes/formatting.php:4456`

```php
function esc_sql( $data ) {
	global $wpdb;
	return $wpdb->_escape( $data );
}
```

## История изменений

- 2.8.0 — Introduced.

## Связанные

Использует: `wpdb::_escape`.
Используется в: `WP_User_Query::parse_orderby`, `WP_Comment_Query::parse_orderby`, `WP_Date_Query::get_sql_for_clause`, `WP_Query::get_posts`, [`_pad_term_counts`](https://chugunov.pro/api-wordpress/functions/_pad_term_counts/), [`_update_post_term_count`](https://chugunov.pro/api-wordpress/functions/_update_post_term_count/), `WP_Date_Query::__construct`, [`wp_load_alloptions`](https://chugunov.pro/api-wordpress/functions/wp_load_alloptions/), [`get_page_by_title`](https://chugunov.pro/api-wordpress/functions/get_page_by_title/), [`get_page_by_path`](https://chugunov.pro/api-wordpress/functions/get_page_by_path/), [`redirect_guess_404_permalink`](https://chugunov.pro/api-wordpress/functions/redirect_guess_404_permalink/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/esc_sql/
