0

Scenario

I had installed php8 and wordpress 5.6 locally over my computer.

Problem

When I run the wordpress, I get Fatal Error.

enter image description here

Question

Anyone of you facing the same problem and how did you solve it? Thanks

LAW WEI LIANG
  • 517
  • 5
  • 11
  • New features in PHP 8 are not compatible with PHP 7 or PHP 5 and usually cause fatal errors. Hence, it is highly recommended that you thoroughly test your site before upgrading to PHP 8. see this link https://make.wordpress.org/core/2020/11/23/wordpress-and-php-8-0/ – Ken Lee Dec 16 '20 at 04:14
  • Another word, wordpress 5.6 is not ready yet for php 8? – LAW WEI LIANG Dec 16 '20 at 04:52
  • According to the above link, WordPress Core aims to be compatible with PHP 8.0 in the 5.6 release. Please pay attention to the word "aims". – Ken Lee Dec 16 '20 at 04:58
  • Arr,,, I skip that "amis" when I am reading the documentation. Noted, to put thing simple, wordpress 5.6 is not ready for php 8.0 yet. Thanks @KenLee. – LAW WEI LIANG Dec 16 '20 at 05:07
  • Your error has nothing to do with php 8. This will break since php 7.2 – Sindhara Dec 16 '20 at 05:29
  • Your Wordpress installation is defaulting to mysql_connect (which was deprecated a long time ago, I think even since php 7.0) because it isn't detecting that mysqli is available. – FoulFoot Dec 16 '20 at 05:44
  • Thanks kuh-chan and FoulFoot. But the question is I get this error when using wordpress version 5.6 with php 8. You try it , I believe you will get the similar error. – LAW WEI LIANG Dec 16 '20 at 05:57
  • When I turn the php version back to php7.4, then this problem will not display anymore. – LAW WEI LIANG Dec 16 '20 at 05:59
  • Yes, always test a new platform before migration. – Ken Lee Dec 17 '20 at 05:03

1 Answers1

1

Your PHP 8 installation does not have a mysqli extension installed.

See possible dupe: Wordpress Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /wp-includes/wp-db.php:1570

I kind of wish WordPress would tell you explicitly that it's missing a usable database extension. The major indicator is the error message itself where WordPress tries to call mysql_connect which was removed ages ago.

WordPress 5.6 core appears to run correctly on PHP 8. Though, the same might not be true of plugins (yet), so you'll want to test them individually.

[Edit] WordPress's database abstraction is written to use either the mysql or mysqli extensions, but the mysql extension was removed in PHP 7.0. The abstraction library does not support PDO, so even if you have the PDO MySQL driver, WordPress will not use it.

PHP8 Local Test

Edit: And to demonstrate a reproduction of the error, I took the same install, but rebuilt my Docker image without the mysqli extension:

Wordpress with mysql_connect error

EPB
  • 3,939
  • 1
  • 24
  • 26