How to convert mysql_real_escape_string to PHP7?
php, wordpress
Solution
you can use wordpress native function
wpdb::_real_escape( string $string )
or
$query = $wpdb->prepare(
"SELECT post_title from $wpdb->posts
WHERE post_title LIKE %s",
"%" . $myTitle . "%"
);
find more here
Problem
I got a Wordpress system running on PHP 7.0.11 using Wordpress. A plugin I want to use does not work and checking the logs does result in PHP Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in… Looking for this error message I have found that the `mysql_real_escape_string()` extension was deprecated. How can I convert this statement to work in PHP 7 and above? ``` $ids = mysql_real_escape_string( $ids ); $result = $wpdb->query( "DELETE FROM $table_name WHERE id IN( $ids )" ); ``` I have found this in the Wordpress docs: `wpdb::_real_escape()`