Warning: This method has been deprecated. Use wpdb::prepare() instead.

wpdb::escape() WordPress Method

The wpdb::escape() method is used to safely escape values for use in SQL queries. This is especially important when using user-provided values in SQL queries, as it helps to prevent SQL injection attacks.

wpdb::escape( string|array $data ) #

Do not use, deprecated.


Description

Use esc_sql() or wpdb::prepare() instead.

Top ↑

See also


Top ↑

Parameters

$data

(string|array)(Required)Data to escape.


Top ↑

Return

(string|array) Escaped data, in the same type as supplied.


Top ↑

Source

File: wp-includes/wp-db.php

	public function escape( $data ) {
		if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) {
			_deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' );
		}
		if ( is_array( $data ) ) {
			foreach ( $data as $k => $v ) {
				if ( is_array( $v ) ) {
					$data[ $k ] = $this->escape( $v, 'recursive' );
				} else {
					$data[ $k ] = $this->_weak_escape( $v, 'internal' );
				}
			}
		} else {
			$data = $this->_weak_escape( $data, 'internal' );
		}

		return $data;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.6.0Use wpdb::prepare()
0.71Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.