#56836 closed defect (bug) (duplicate)
PHP 8.1 Deprecation Warning for mysqli_real_connect
Reported by: | nickchomey | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 6.0.2 |
Component: | Database | Keywords: | php81 |
Focuses: | Cc: |
Description
I'm getting these deprecation warnings in the debug.log
[16-Oct-2022 23:14:52 UTC] PHP Deprecated: mysqli_real_connect(): Passing null to parameter #5 ($database) of type ?string is deprecated in /home/seeingtheforest.net/public_html/wp-includes/wp-db.php on line 1753 [16-Oct-2022 23:14:52 UTC] PHP Deprecated: mysqli_real_connect(): Passing null to parameter #6 ($port) of type ?int is deprecated in /home/seeingtheforest.net/public_html/wp-includes/wp-db.php on line 1753 [16-Oct-2022 23:14:52 UTC] PHP Deprecated: mysqli_real_connect(): Passing null to parameter #7 ($socket) of type ?string is deprecated in /home/seeingtheforest.net/public_html/wp-includes/wp-db.php on line 1753
I'm using PHP 8.1, so assume it is due to that. It probably happens in 8.0 as well.
If I trace the error with Xdebug, I can see that the problem is
a) null is simply hardcoded for param 5
b) port and socket are set to null if they aren't included in wp-config.php e.g. define('DB_HOST', "localhost");
If I manually change param 5 to ""
and
$port = ""; $socket = "";
in wp-includes/wp-db.php -> parse_db_host()
then the problem goes away.
Change History (7)
#3
@
23 months ago
- Keywords php81 removed
I've decided to close this as well as remove my comment from #54877 as it seems like there's a bug in Litespeed's lsphp81 that isn't treating mysqli_real_connect
's parameters as nullable.
#5
@
23 months ago
Hi there, welcome back to WordPress Trac!
Just adding some context from #54877:
- The
$database
,$port
, and$socket
parameters ofmysqli_real_connect()
should actually be nullable, as they arenull
by default in PHP source, per comment:15:ticket:54877. - The issue might have to do with using LiteSpeed PHP, per comment:42:ticket:54877.
P.S. Ah, it looks like this is already noted above.
Duplicate of #54877.
Closing this as it is already an issue here https://core.trac.wordpress.org/ticket/54877#comment:42
Though, just one clarification - it should be
$port = 0
since it is an int.