Skip to content

Commit efeb120

Browse files
committed
Syncs DB connect code with WP Core 4.9
Pulls in WordPress/WordPress@dbd93dd Which fixes https://core.trac.wordpress.org/ticket/41722
1 parent f5f712b commit efeb120

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

lib/db.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,23 @@ public function db_connect( $allow_bail = true ) {
3939
if ( $this->use_mysqli ) {
4040
$this->dbh = mysqli_init();
4141

42-
// mysqli_real_connect doesn't support the host param including a port or socket
43-
// like mysql_connect does. This duplicates how mysql_connect detects a port and/or socket file.
44-
$port = null;
45-
$socket = null;
46-
$host = $this->dbhost;
47-
$port_or_socket = strstr( $host, ':' );
48-
if ( ! empty( $port_or_socket ) ) {
49-
$host = substr( $host, 0, strpos( $host, ':' ) );
50-
$port_or_socket = substr( $port_or_socket, 1 );
51-
if ( 0 !== strpos( $port_or_socket, '/' ) ) {
52-
$port = intval( $port_or_socket );
53-
$maybe_socket = strstr( $port_or_socket, ':' );
54-
if ( ! empty( $maybe_socket ) ) {
55-
$socket = substr( $maybe_socket, 1 );
56-
}
57-
} else {
58-
$socket = $port_or_socket;
59-
}
42+
$host = $this->dbhost;
43+
$port = null;
44+
$socket = null;
45+
$is_ipv6 = false;
46+
47+
if ( $host_data = $this->parse_db_host( $this->dbhost ) ) {
48+
list( $host, $port, $socket, $is_ipv6 ) = $host_data;
49+
}
50+
51+
/*
52+
* If using the `mysqlnd` library, the IPv6 address needs to be
53+
* enclosed in square brackets, whereas it doesn't while using the
54+
* `libmysqlclient` library.
55+
* @see https://bugs.php.net/bug.php?id=67563
56+
*/
57+
if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
58+
$host = "[$host]";
6059
}
6160

6261
// Set SSL certs if we want to use secure DB connections
@@ -97,7 +96,8 @@ public function db_connect( $allow_bail = true ) {
9796
if ( $this->dbh->connect_errno ) {
9897
$this->dbh = null;
9998

100-
/* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
99+
/*
100+
* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
101101
* - We haven't previously connected, and
102102
* - WP_USE_EXT_MYSQL isn't set to false, and
103103
* - ext/mysql is loaded.

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ For detailed installation instructions, please read the [standard installation p
6868
= 1.1.5 =
6969

7070
* PHP backwards compatibility with versions prior to 5.5
71+
* Syncs DB connect code with WP Core 4.9 (Fixes https://core.trac.wordpress.org/ticket/41722)
7172

7273
= 1.1.4 =
7374

0 commit comments

Comments
 (0)