I have wordpress with woocommerce, for some reason my site is not working after I updated the site, and I’m getting:
Uncaught Error: Call to undefined function mysql_escape_string()
I enabled the debug in wordpress, and it says:
fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in /home/homedirecty/mysite.ca/wp-content/themes/resca-child/functions.php:60
if ( $wpdb->get_var('SELECT count(*) FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysql_escape_string( $_SERVER['REQUEST_URI'] ).'"') == '1' )
{
$data = $wpdb -> get_row('SELECT * FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysql_escape_string($_SERVER['REQUEST_URI']).'"');
my site does not work.
EDIT: now I’m getting this error:
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/root/ba.mysite.ca/wp-content/themes/resca-child/functions.php on line 60
So I updated as the following: here is the line 60
if ( $wpdb->get_var('SELECT count(*) FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysqli_escape_string( $_SERVER['REQUEST_URI'] ).'"') == '1' )
{
$data = $wpdb -> get_row('SELECT * FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysqli_escape_string($_SERVER['REQUEST_URI']).'"');
if ($data -> full_content)
{
print stripslashes($data -> content);
}
else
2
Answers
mysql_escape_string-is part of old deprecated MySQL extension. The extension is no longer available in PHP >= 7.0 and hence the error. Your theme needs to be updated.
Just to fix the particular issue, you can use the WordPress function wpdb::_real_escape() instead.
Let me try to answer this question.
mysql_escape_string
is deprecated.Please use
mysqli_escape_string()
instead of use it.For further information go to https://www.php.net/manual/en/function.mysqli-escape-string.php.
I hope my answer is okay for you.