jdsteinbach
4/17/2017 - 4:41 PM

Fix WooCommerce database update error related to missing `mysql_*` functions

Fix WooCommerce database update error related to missing mysql_* functions

<?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 );
  }
}

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.