[wp-trac] [WordPress Trac] #51988: Call to undefined function mysql_connect()
WordPress Trac
noreply at wordpress.org
Sat Feb 18 19:04:26 UTC 2023
#51988: Call to undefined function mysql_connect()
-------------------------------------------------+-------------------------
Reporter: bgin | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 6.3
Component: Database | Version: 5.6
Severity: normal | Resolution:
Keywords: php8 has-patch needs-testing has- | Focuses:
testing-info |
-------------------------------------------------+-------------------------
Changes (by SergeyBiryukov):
* keywords: php8 needs-patch => php8 has-patch needs-testing has-testing-
info
* milestone: Future Release => 6.3
Comment:
Replying to [comment:16 SergeyBiryukov]:
> {{{
> Fatal error: Uncaught Error: Call to undefined function mysql_connect()
in wp-includes/class-wpdb.php:1963
> }}}
>
> I was able to reproduce this error message by accidentally using a non-
thread safe version of PHP as an Apache module, instead of the thread safe
version recommended in that case.
It appears that simply disabling the `mysqli` PHP extension on an existing
installation has the same effect.
[attachment:"51988.diff"] implements comment:17 and moves some
conditionals around to simplify the logic and avoid repeating code. It
turned out that `wpdb::bail()` would also need to check if `mysql_error()`
exists to avoid a fatal error.
Taking a step back though, it seems that checking for this in
`wpdb::db_connect()` is perhaps a bit too late in the request, as we have
a dedicated function, `wp_check_php_mysql_versions()`, which runs earlier
on each request.
In my testing, `wp_check_php_mysql_versions()` does not bail here due to
the `extension_loaded( 'mysqlnd' )` check added in [36434] / #33261. The
`mysqlnd` extension is reported as available on my environment, but does
not appear to work as a fallback in case `mysqli` is not available, at
least not on PHP 8.0+.
So [attachment:"51988.alt.diff"] is an alternative patch which checks if
either `mysqli_connect()` or `mysql_connect()` function exists, and
returns early from `wp_check_php_mysql_versions()` otherwise with a more
friendly message.
To test:
* Use PHP 8.0 or later.
* Disable the `mysqli` extension on an existing WordPress installation.
* You'll get a `Call to undefined function mysql_connect()` fatal error.
With the patch (either of them), you'll get a message instead of a fatal
error:
> Your PHP installation appears to be missing the MySQL extension which is
required by WordPress.
>
> Please check that the `mysqli` PHP extension is installed and enabled.
>
> If you are unsure what these terms mean you should probably contact your
host. If you still need help you can always visit the
[https://wordpress.org/support/forums/ WordPress Support Forums].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51988#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list