Support empty DB names in LoadBalancer more fully
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 4 Nov 2014 00:52:42 +0000 (16:52 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 4 Nov 2014 00:52:42 +0000 (16:52 -0800)
* This convention to avoid selecting a DB is already supported for
  new connections but not when an existing foreign wiki connection
  is reused. This avoids giving PHP notices.

Change-Id: Ic6e9ed031bc8ea6d6f519b6998f0414364c087d0

includes/db/LoadBalancer.php

index 186915c..eeb2fec 100644 (file)
@@ -655,7 +655,9 @@ class LoadBalancer {
                        $conn = reset( $this->mConns['foreignFree'][$i] );
                        $oldWiki = key( $this->mConns['foreignFree'][$i] );
 
-                       if ( !$conn->selectDB( $dbName ) ) {
+                       // The empty string as a DB name means "don't care".
+                       // DatabaseMysqlBase::open() already handle this on connection.
+                       if ( $dbName !== '' && !$conn->selectDB( $dbName ) ) {
                                $this->mLastError = "Error selecting database $dbName on server " .
                                        $conn->getServer() . " from client host " . wfHostname() . "\n";
                                $this->mErrorConnection = $conn;