From f1425f3ea26ace222e0bbcc0486dc361a56f87d0 Mon Sep 17 00:00:00 2001 From: mglaser Date: Mon, 27 Jan 2014 10:10:50 +0100 Subject: [PATCH] Make MySQLi work with non-standard port Other than mysql_connect, mysqli_real_connect expects an explicit port parameter. So we need to parse the port out of $realServer. Note it is not possible to just use $wgDBport, since that is set to 5432 as a defalt and would break all existing sites using mysqli on standard port. This change is IPv6 safe. Bug: 58153 Change-Id: I8fe191b930b26bce3c863b1953b237cb4a889c6e --- includes/db/DatabaseMysqli.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/db/DatabaseMysqli.php b/includes/db/DatabaseMysqli.php index d41f3e4c69..0dc1890eac 100644 --- a/includes/db/DatabaseMysqli.php +++ b/includes/db/DatabaseMysqli.php @@ -57,6 +57,17 @@ class DatabaseMysqli extends DatabaseMysqlBase { . " have you compiled PHP with the --with-mysqli option?\n" ); } + // Other than mysql_connect, mysqli_real_connect expects an explicit port + // parameter. So we need to parse the port out of $realServer + $port = null; + $hostAndPort = IP::splitHostAndPort( $realServer ); + if ( $hostAndPort ) { + $realServer = $hostAndPort[0]; + if ( $hostAndPort[1] ) { + $port = $hostAndPort[1]; + } + } + $connFlags = 0; if ( $this->mFlags & DBO_SSL ) { $connFlags |= MYSQLI_CLIENT_SSL; @@ -83,7 +94,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { usleep( 1000 ); } if ( $mysqli->real_connect( $realServer, $this->mUser, - $this->mPassword, $this->mDBname, null, null, $connFlags ) + $this->mPassword, $this->mDBname, $port, null, $connFlags ) ) { return $mysqli; } -- 2.20.1