@@ -39,24 +39,23 @@ public function db_connect( $allow_bail = true ) {
39
39
if ( $ this ->use_mysqli ) {
40
40
$ this ->dbh = mysqli_init ();
41
41
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] " ;
60
59
}
61
60
62
61
// Set SSL certs if we want to use secure DB connections
@@ -97,7 +96,8 @@ public function db_connect( $allow_bail = true ) {
97
96
if ( $ this ->dbh ->connect_errno ) {
98
97
$ this ->dbh = null ;
99
98
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:
101
101
* - We haven't previously connected, and
102
102
* - WP_USE_EXT_MYSQL isn't set to false, and
103
103
* - ext/mysql is loaded.
0 commit comments