Skip to content

Instantly share code, notes, and snippets.

@jdsteinbach
Last active April 17, 2017 16:54
Show Gist options
  • Save jdsteinbach/0fe46787c5cda6691c7bfc34ba8ae497 to your computer and use it in GitHub Desktop.
Save jdsteinbach/0fe46787c5cda6691c7bfc34ba8ae497 to your computer and use it in GitHub Desktop.
Fix WooCommerce database update error related to missing `mysql_*` functions

Fix WooCommerce's updater

Quick Intro

If you've just updated to WooCommerce 3.0.* and the database updater fails (the whole page threw a 500 error for me), drop the mysql-escape-string-fix.php file into your /wp-content/mu-plugins/ directory and give it a try.

More Info

I got the following error in my debug.log when this update failed:

PHP Fatal error:  Uncaught Error: Call to undefined function mysql_real_escape_string() in /wp-content/themes/mystile/functions/admin-interface.php:111

Turns out my theme was looking for a PHP function mysql_real_escape_string() that got deprecated back in PHP 4.3 and completely dropped from PHP 7. Providing a safe alias for it solved the problem & let me get my WooCommerce store updated.

<?php
/**
* Provide working aliases for old PHP functions that aren't present in PHP7
*/
if ( ! function_exists( 'mysql_escape_string' ) ) {
function mysql_escape_string( $string ) {
return mysqli_escape_string( $string );
}
}
if ( ! function_exists( 'mysql_real_escape_string' ) ) {
function mysql_real_escape_string( $string ) {
return mysqli_real_escape_string( $string );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment