If you see something like this error, “undefined function mysql_connect()”, in your logs it means your WordPress site is calling a function to a deprecated extension called mysql_Connect:
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /wp-includes/wp-db.php:1645
As its name implies, it’s used to call connections to the database in older versions of PHP.
According to the PHP Manual:
This 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.www.php.net
Here’s the example usage:
mysql_connect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = FALSE [, int $client_flags = 0 ]]]]] ) : resource
This error will most likely crop up if you upgrade your server’s PHP version from 5.X to 7.X (or migrate to new hardware). This function actually works just fine on PHP 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:
The most common reason for the presence of “undefined function mysql_connect()” in your error logs or debug output is this one line in
Removing that line should fix the issue. If it doesn’t, hop into your terminal and seach for
WP_USE_EXT_MYSQL through your file system (with something like
ack wp_use_ext_mysql -l) to hunt it down in your plugin and theme files.
Though it’s worth consulting your developer, or the developer of the related theme or plugin, to see why it was there in the first place. They may need to update the code to use something like
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.
And that’s that.
On a completely unrelated note, when you’re about ready to take a break from debugging lame PHP errors, I’ve put together a free 36 minute video crash course on dominating Google Pagespeed mobile scores with WordPress here (no email required, just click here and watch). It’s my gift to you to help you rank – I want nothing in return, just remember me when you’re at the top.