PHP: mysql_real_escape_string is not working in version 7.2

Dear Experts,

I have the following codes used to work in PHP 5.0 and suddenly it stop working after I upgraded to PHP 7.2
$query_sql = "SELECT * FROM wp_posts WHERE post_title = %s ORDER BY post_title;";
$query = sprintf($query_sql, mysql_real_escape_string($name));
$postquery = $wpdb->get_results("{$wpdb->prepare($query)}");

echo 'Rows: ' . count($postquery);

The row count return 0.

Please help. Thank you in advance.
Van NAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


That was removed from v7

You should use PDO_MySQL or MySQLi instead
Van NAuthor Commented:
Hi lenamtl,

Would you show me some sample codes?

Hi, I'm using PDO.

You will need to adapt all the MySQL request, PHP code and DB connection.
If you are using PHP Storm there is a way to find the code which is not compatible with v7.

You can check a good tutorial here about PDO

You will learn how it work with the prepared statement
DB connection and everything you will need to know,  there is some learning curve

There are some great tutorial on Udemy

I just realized that you are using WP, so you will need to update Wordpress to the latest version and adapt all your custom code.
5 Ways Acronis Skyrockets Your Data Protection

Risks to data security are risks to business continuity. Businesses need to know what these risks look like – and where they can turn for help.
Check our newest E-Book and learn how you can differentiate your data protection business with advanced cloud solutions Acronis delivers

Van NAuthor Commented:

I already upgraded the WordPress to the current version 5.0.3.

Where this MySQL request come from?
Van NAuthor Commented:
WordPress custom template.
Ok then you will need to adapt all your custom template PHP code / MySQL request code to be compatible
or you can use a new theme

This can take a lot of time depending of the theme so I would use a new one and adapt or hire a dev to fix it

There is a tool that you can use to check PHP compatibility

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Van NAuthor Commented:
Got it. Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.