WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 6 weeks ago

#51988 reopened defect (bug)

Call to undefined function mysql_connect()

Reported by: bgin Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.6
Component: Database Keywords: php8
Focuses: Cc:

Description

Call to undefined function mysql_connect() in D:\xamppCF\htdocs\wp-includes\wp-db.php:1685

Change History (14)

#1 @desrosj
4 months ago

  • Component changed from General to Database
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi @bgin,

Welcome to Trac! I'm sorry you are experiencing issues with WordPress 5.6. However, this Trac instance is not for general support requests.

The information provided is also not enough to begin troubleshooting your exact issue.

However, this does not appear to be an issue with PHP 8. The mysql_connect() function was deprecated in PHP 5.5 and removed in 7.0.0 (see the PHP documentation). It's possible that the PHP installation you have set up in XAMPP is not built correctly, causing WordPress to incorrectly use mysql instead of mysqli, which the original extension.

If you require further support, I recommend opening a support topic in the WordPress.org Support Forums.

#2 @SergeyBiryukov
4 months ago

  • Summary changed from wordpress 5.6 not ok with php 8 to Call to undefined function mysql_connect()

Just to clarify a bit more, since version 3.9, WordPress uses mysqli on PHP 5.5 or later instead of the deprecated mysql extension. See this post for more context: MySQL in WordPress 3.9.

I would suggest checking that the mysqli extension is available and the WP_USE_EXT_MYSQL constant is not defined in wp-config.php.

#3 @dimadin
4 months ago

Another ticket (#52001) was opened for the same error, again on WP 5.6 / PHP 8.

#4 @desrosj
4 months ago

#52001 was marked as a duplicate.

#5 @desrosj
4 months ago

#52001 was marked as a duplicate.

#6 @desrosj
4 months ago

From @ipajen on #52001:

I was using PHP 7.4 (where the mysql_connect() was removed already and everything worked fine) until before upgrading to PHP 8. No changes has been made except upgrading to PHP 8. So the question is why does it want to use mysql_connect instead of correct mysqli. Got 3 word press installltions on same hosting and all has the same problem, one of is very newly installed.

As of the release of PHP 8, the @ operator will no longer suppress errors fatal errors.

Looking at the code in WordPress, unless WP_DEBUG mode is enabled, the @ operator preceded the mysql_connect() call. In previous versions of PHP, it's likely that this just failed silently, and just happened to work on accident.

As noted above, if mysqli_connect() is present on the server running WordPress, it will always be used unless WP_USE_EXT_MYSQL is defined as true.

The only ways to encounter this issue would be a PHP install with mysqli missing or improperly configured, or the WP_USE_EXT_MYSQL being set to true. I would search in the mu-plugins directory, check your active plugins/wp-config.php file, or reach out to your hosting provider for more help. It's possible the hosting environment has incompatibilities with PHP 8 at the system level.

This ticket was mentioned in Slack in #core by desrosj. View the logs.


4 months ago

#8 @SergeyBiryukov
4 months ago

  • Milestone set to 5.6.1
  • Resolution invalid deleted
  • Status changed from closed to reopened

Replying to desrosj:

As of the release of PHP 8, the @ operator will no longer suppress errors fatal errors.

Looking at the code in WordPress, unless WP_DEBUG mode is enabled, the @ operator preceded the mysql_connect() call. In previous versions of PHP, it's likely that this just failed silently, and just happened to work on accident.

Since the error is now more prominent with PHP 8, I think we could display a better error message here for clarity, with some action items for the user to check, and a link to support forums.

#9 @SergeyBiryukov
4 months ago

  • Keywords php8 added

#10 @hellofromTonya
4 months ago

display a better error message here for clarity, with some action items for the user to check, and a link to support forums.

@SergeyBiryukov What are you envisioning for this?

  • Better error message or doing it wrong?
  • Will it be for PHP 8 only? Or do we want to check if the function exists and, if no, then through an error with the additional info and support forums link?
  • What "action items for the user to check" should we include?

#11 @ipajen
4 months ago

Following links helped to find the error for my hosting provider (my hostingprovider is using clodlinux that will provide a fix soon)

To test mysqli connection on server
https://www.php.net/manual/en/function.mysqli-connect.php

To see if mysqli is enabled
https://www.php.net/manual/en/function.phpinfo.php

This ticket was mentioned in Slack in #core by metalandcoffee. View the logs.


3 months ago

#13 @whyisjake
2 months ago

  • Milestone changed from 5.6.1 to 5.6.2

Since we are coming up on the 5.6.1 release date, I am going to push this to the next release while we work out a change for this issue.

#14 @desrosj
8 weeks ago

  • Milestone changed from 5.6.2 to Future Release

5.6.2 RC is going to be packaged in a few hours. Since this one still lacks a patch, I'm going to punt to Future Release.

Note: See TracTickets for help on using tickets.