Merge "Make MySQLi work with non-standard port"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 14 Mar 2014 22:43:25 +0000 (22:43 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 14 Mar 2014 22:43:25 +0000 (22:43 +0000)
1  2 
includes/db/DatabaseMysqli.php

@@@ -57,6 -57,17 +57,17 @@@ class DatabaseMysqli extends DatabaseMy
                                . " 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 +94,7 @@@
                                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;
                        }
         */
        protected function mysqlFieldType( $res, $n ) {
                $field = $res->fetch_field_direct( $n );
 +
                return $field->type;
        }
  
        protected function mysqlPing() {
                return $this->mConn->ping();
        }
 +
 +      /**
 +       * Give an id for the connection
 +       *
 +       * mysql driver used resource id, but mysqli objects cannot be cast to string.
 +       */
 +      public function __toString() {
 +              if ( $this->mConn instanceof Mysqli ) {
 +                      return (string)$this->mConn->thread_id;
 +              } else {
 +                      // mConn might be false or something.
 +                      return (string)$this->mConn;
 +              }
 +      }
  }