How To: Fix PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /wp-includes/wp-db.php

How To: Fix Uncaught Error: Call to undefined function mysql_connect() in /wp-includes/wp-db.php

If you see something like this error in your logs it means your WordPress site is calling a deprecated function:

PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /wp-includes/wp-db.php:1645

According to the PHP Manual:

WarningThis extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_connect()
PDO::__construct()

PHP Manual | www.php.net

This most likely will happen if you upgrade your server’s PHP version from 5.X to 7.X. This function actually works on 5.6, but not on 7.0 and above. The side-effects to your site will range from just being an error in the logs all the way to bringing the site down:

How To: Fix Uncaught Error: Call to undefined function mysql_connect() in /wp-includes/wp-db.php

The most common reason for this is the presence of one line in wp-config.php:

define('WP_USE_EXT_MYSQL', true);

Removing that line will fix the issue.

Though it’s worth consulting your developer to see why it was there in the first place, they may need to update the code to use something like mysqli_connect() instead.

That WP_USE_EXT_MYSQL define is most commonly used to add support for older plugins (like some versions of Shopp and Social Streams for example) so it’s a good idea to at least run through your site to test for broken functionality after removing that line.