17

I am in big trouble. I installed a nulled version of woocommerce cart based shipping plugin and i found it not relevant according to my requiremnet and deleted that plugin from plugins area. After deleting that plugin my site went down. Its continuously showing me Fatal error:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/dev/public_html/new/wp-includes/wp-db.php:1570
Stack trace:
#0 /home/dev/public_html/new/wp-includes/wp-db.php(658): wpdb->db_connect()
#1 /home/dev/public_html/new/wp-includes/load.php(404): wpdb->__construct('dev_test', 'password', 'dev_test_ne...', 'localhost')
#2 /home/dev/public_html/new/wp-settings.php(107): require_wp_db()
#3 /home/dev/public_html/new/wp-config.php(82): require_once('/home/dev/p...')
#4 /home/dev/public_html/new/wp-load.php(37): require_once('/home/dev/p...')
#5 /home/dev/public_html/new/wp-blog-header.php(13): require_once('/home/dev/p...')
#6 /home/dev/public_html/new/index.php(17): require('/home/dev/p...')
#7 {main} thrown in /home/dev/public_html/new/wp-includes/wp-db.php on line 1570

I tried replacing all core files excluding wp-config.php and wp-content folder. Still I am getting the same error.

Also, i tried renameing plugins folder but the error is there.

Can you guys suggest me how i can get my site back.

xarlymg89
  • 2,552
  • 2
  • 27
  • 41
Thomas
  • 417
  • 1
  • 5
  • 17
  • where is the website hosted ? If you are using web hosting service you could restore a backup and go from there. – Necvetanov Jun 30 '17 at 08:20
  • are you deleted before deactivated the plugin ? – WP Learner Jun 30 '17 at 08:21
  • Possible duplicate of [Undefined function mysql\_connect()](https://stackoverflow.com/questions/13825108/undefined-function-mysql-connect) – Dan Hastings Jun 30 '17 at 08:22
  • @user2584538 i deactivated plugin from the plugins area in admin panel and deleted it. That's it. – Thomas Jun 30 '17 at 08:54
  • Can you reinstall the plugin and see if that restores fuctionality? –  Jun 30 '17 at 09:10
  • I tried to put the plugin files in plugins folder but i am not able to activate it because i cant access site admin as well – Thomas Jun 30 '17 at 09:37
  • Of course you need mysql_connect to login. Can you access the database directly? –  Jun 30 '17 at 10:29
  • Sorry, but I have realized that restoring the plugin cannot possible fix this problem as the database connection is made before the plugins are loaded. WordPress needs to read the database to determine the active plugins. So, this error will occur before the plugin has a chance to load. I am stupid! –  Jun 30 '17 at 12:04

9 Answers9

26

I encountered this problem upgrading from PHP 5 to PHP 7 (on Windows). The problem was mysqli PHP extension was not enabled. If mysqli is not available Wordpress 5+ detects this and will instead attempt to connect to the database with deprecated mysql_connect() calls. This leads to a very misleading error message about mysql_connect() function not being available (since we don't want this function).

In php.ini make sure extension_dir is set (use full directory name) and mysqli extension is enabled

extension_dir = "C:\php-7.3.10\ext"
...
extension=mysqli

To double check what extensions are active you can run the following code

<pre>
<?php print_r(get_loaded_extensions()); ?>
</pre>
Robb Hoff
  • 1,719
  • 2
  • 17
  • 32
  • 2
    When using IIS you must restart the site or the app pool otherwise the setting will not take effect – Tareq Oct 24 '21 at 06:26
  • In Windows 10 Professional, in IIS in the Connections pane, I had to right-click the computer name (topmost item) and select Stop, then do it again for Start. Just restarting the site did not cause the php.ini changes to be taking into effect. – Buzzy Hopewell Mar 23 '23 at 02:10
8

Possible error sources:

You can set

define('WP_USE_EXT_MYSQL', true);

in your wp-config.php file to make WordPress use the mysqli extension.

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Schakko
  • 154
  • 5
  • 1
    Doesn't seem to work for all plugins. I had a problem with a WP blog after I migrated it to a server with PHP 7.3. And I isolated the problem due to a plugin folder named 'cystats'. However this define doesn't make it work. I had to remove the plugin at the end. – xarlymg89 Oct 10 '19 at 20:36
6

It happens for me when I switch from 5.6 php to 7.0.

Just enable "mysqli" in your select php version if you use cPanel.

  • This is what solved the issue for me. Quite straightforward and easy suggestion. It was enabled by default in direct admin php selector but for some reason for this 1 site it wasn't. Enabling it solved the issue. – DonKoko Oct 14 '20 at 10:19
3

Just registered to give a big thank you for the solution of enabling mysqli. I have been struggling to get WordPress running on a Synology for the past 3.5 hours and this finally fixed my dreaded "The site is experiencing technical difficulties."

For any other Synology users ending up in this topic after trying to find a solution, to fix this on Synology, you need to...

  • Go to Web Station
  • Select PHP Settings
  • Double-click the PHP profile you are using (or click once and choose [Edit])
  • Select General Settings and scroll to the extensions list
  • Find mysqli and enable by placing a checkmark
  • Push the [OK] button (no restart required)
Misophoniq
  • 39
  • 1
  • 1
    This is not really an answer to the question on this page. Perhaps you should leave a comment on the answer that suggested enabling mysqli and upvote their answer. – Meezaan-ud-Din Apr 05 '20 at 11:24
2

Please check your wp-config.php file for the following line:

define('WP_USE_EXT_MYSQL', true);

If you find it, delete the line. Your problem should be fixed.

If not, you can tick nd_mysqli extension in the PHP 7 configuration, and disable the mysqli extension on Cpanel -> Select PHP version.

Source:

https://wordpress.org/support/topic/database-cache-causing-503-errors-when-upgrading-to-php-7/

Hope this helps. :)

Simon
  • 195
  • 2
  • 4
  • 18
0

The error seems be simple, mysql_* functions are not enabled. Check with phpinfo() if these functions are truly disabled, and if yes, enable it. If no, there are some problems in the code that you are using, but if you have replaced all files as you write, is most probably the first option.

Ryosaku
  • 453
  • 4
  • 14
  • I checked phpinfo() and there is no issue in it.. There are many more websites hosted on same server.. They are working fine.. – Thomas Jun 30 '17 at 08:56
  • Have you tried to do a clean install and then replace all files? – Ryosaku Jun 30 '17 at 09:51
  • You mean to install fresh wp and upload my theme and plugins file? – Thomas Jun 30 '17 at 09:53
  • Yes, exatly. The idea is do a full backup (files+db), then a fresh install and finally replace all files. When you have found the problem, you can isolate it on your old system, and fix it without lose anything. Or you can reconfigure it completely, depending on your preferences. – Ryosaku Jun 30 '17 at 10:22
  • Yes, i tried this.. Also, i tried to setup the same site on other server and its working fine there.. – Thomas Jul 03 '17 at 11:47
0

Just had a similar problem with a cpanel multiphp instance. Tried just about everything but while cpanel/whm was saying all was fine, the site would crash when 7.x was activated.

In the end, it was the .htaccess file. We renamed and let Cpanel regenerate and all is good.

Hope this helps someone out there as it took some time to resolve here.

Paul R
  • 1
0

i had same kind of issue for my web hosting client at magicworkshost , i have updated php version from 5.6 to 7.3 and issue resolved successfully.

Thanks

0
sudo apt-get install php7.4-mysql
sudo service apache2 restart
Laurent Debricon
  • 4,307
  • 2
  • 24
  • 26