On this page
wpdb::_real_escape( string $string ): string
Real escape, using mysqli_real_escape_string() or mysql_real_escape_string().
Description
See also
Parameters
$stringstring Required-
String to escape.
Return
string Escaped string.
Source
File: wp-includes/class-wpdb.php. View all references
public function _real_escape( $string ) {
if ( ! is_scalar( $string ) ) {
return '';
}
if ( $this->dbh ) {
if ( $this->use_mysqli ) {
$escaped = mysqli_real_escape_string( $this->dbh, $string );
} else {
$escaped = mysql_real_escape_string( $string, $this->dbh );
}
} else {
$class = get_class( $this );
wp_load_translations_early();
/* translators: %s: Database access abstraction class, usually wpdb or a class extending wpdb. */
_doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), '3.6.0' );
$escaped = addslashes( $string );
}
return $this->add_placeholder_escape( $escaped );
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::add_placeholder_escape() wp-includes/class-wpdb.php | Adds a placeholder escape string, to escape anything that resembles a printf() placeholder. |
| wp_load_translations_early() wp-includes/load.php | Attempt an early load of translations. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| _doing_it_wrong() wp-includes/functions.php | Marks something as being incorrectly called. |
Used By
| Used By | Description |
|---|---|
| wpdb::_escape() wp-includes/class-wpdb.php | Escapes data. Works on arrays. |
| wpdb::escape_by_ref() wp-includes/class-wpdb.php | Escapes content by reference for insertion into the database, for security. |
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/_real_escape