Fatal error with mysql_connect after upgrading to PHP 7

When you update your WordPress site under PHP 7, the following errors may appear :

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in ...wp-includes/wp-db.php:1665
Stack trace: #0 ...wp-includes/wp-db.php(632): wpdb->db_connect() #1 ...wp-includes/load.php(425)
Fatal error: Uncaught Error: Call to undefined function wp_kses_normalize_entities() in .../wp-includes/formatting.php:4316
Stack trace: #0 .../wp-includes/class-wp-fatal-error-handler.php(190)

Where does this error come from?

By upgrading to PHP 7.3 (or rather from PHP 7.0.0 onwards), the mysql_connect extension has been removed. It was already deprecated since PHP 5.5.0.

Instead, it is recommended to use the mysqli extensions to connect to a database. This extension is more powerful and more secure.

What can be done to solve this problem?

Depending on the origin of the error, there are several solutions:

  • Contact your web host and ask if mysqli extensions are enabled.
  • Check that you have mysqi enabled on your hosting:
    $var_mysqli = function_exists('mysqli_connect'); var_dump($var_mysqli);
  • Test your connection with mysqli :
    $mysqli_connection = new MySQLi('nom_d_hôte', 'nom_utilisateur', 'mot_de_passe', 'nom_de_la_base_de_données');
  • Check your wp-config.php file and verify that the following variable :
    define(‘WP_USE_EXT_MYSQL’, false);
    is set to “false”.
Leave a Comment

Your email address will not be published.

You may also like