Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert mysql_real_escape_string to PHP7?

Tags:

php

wordpress

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()

like image 551
Marian Rick Avatar asked Oct 19 '16 07:10

Marian Rick


1 Answers

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

like image 151
viral barot Avatar answered Sep 30 '22 20:09

viral barot