Merge "MySQL connect: Parse the Unix domain socket path correctly"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 19 Aug 2019 10:47:45 +0000 (10:47 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 19 Aug 2019 10:47:45 +0000 (10:47 +0000)
1  2 
includes/libs/rdbms/database/DatabaseMysqli.php

@@@ -40,7 -40,15 +40,7 @@@ class DatabaseMysqli extends DatabaseMy
         * @return mysqli_result|bool
         */
        protected function doQuery( $sql ) {
 -              $conn = $this->getBindingHandle();
 -
 -              if ( $this->getFlag( self::DBO_NOBUFFER ) ) {
 -                      $ret = $conn->query( $sql, MYSQLI_USE_RESULT );
 -              } else {
 -                      $ret = $conn->query( $sql );
 -              }
 -
 -              return $ret;
 +              return $this->getBindingHandle()->query( $sql );
        }
  
        /**
                        );
                }
  
-               // Other than mysql_connect, mysqli_real_connect expects an explicit port
-               // and socket parameters. So we need to parse the port and socket out of
-               // $realServer
+               // Other than mysql_connect, mysqli_real_connect expects an explicit port number
+               // e.g. "localhost:1234" or "127.0.0.1:1234"
+               // or Unix domain socket path
+               // e.g. "localhost:/socket_path" or "localhost:/foo/bar:bar:bar"
+               // colons are known to be used by Google AppEngine,
+               // see <https://cloud.google.com/sql/docs/mysql/connect-app-engine>
+               //
+               // We need to parse the port or socket path out of $realServer
                $port = null;
                $socket = null;
                $hostAndPort = IP::splitHostAndPort( $realServer );
@@@ -67,9 -80,9 +72,9 @@@
                        if ( $hostAndPort[1] ) {
                                $port = $hostAndPort[1];
                        }
-               } elseif ( substr_count( $realServer, ':' ) == 1 ) {
-                       // If we have a colon and something that's not a port number
-                       // inside the hostname, assume it's the socket location
+               } elseif ( substr_count( $realServer, ':/' ) == 1 ) {
+                       // If we have a colon slash instead of a colon and a port number
+                       // after the ip or hostname, assume it's the Unix domain socket path
                        list( $realServer, $socket ) = explode( ':', $realServer, 2 );
                }