$this->reportConnectionError( $error );
}
- if ( $dbName != '' ) {
+ if ( strlen( $dbName ) ) {
MediaWiki\suppressWarnings();
$success = $this->selectDB( $dbName );
MediaWiki\restoreWarnings();
throw new DBAccessError();
}
- if ( $domainOverride->getDatabase() !== null ) {
+ // Handle $domainOverride being a specified or an unspecified domain
+ if ( $domainOverride->getDatabase() === null ) {
+ // Normally, an RDBMS requires a DB name specified on connection and the $server
+ // configuration array is assumed to already specify an appropriate DB name.
+ if ( $server['type'] === 'mysql' ) {
+ // For MySQL, DATABASE and SCHEMA are synonyms, connections need not specify a DB,
+ // and the DB name in $server might not exist due to legacy reasons (the default
+ // domain used to ignore the local LB domain, even when mismatched).
+ $server['dbname'] = null;
+ }
+ } else {
$server['dbname'] = $domainOverride->getDatabase();
$server['schema'] = $domainOverride->getSchema();
}
$db = $lb->getConnection( DB_MASTER, [], '' );
$this->assertEquals(
- $wgDBname,
+ '',
$db->getDomainId(),
- 'Main domain ID handle used; same DB name'
+ 'Null domain ID handle used'
);
$this->assertEquals(
- $wgDBname,
+ '',
$db->getDBname(),
- 'Main domain ID handle used; same DB name'
+ 'Null domain ID handle used'
);
$this->assertEquals(
'',
$dbname = 'unittest-domain'; // explodes if DB is selected
$factory = $this->newLBFactoryMulti(
[ 'localDomain' => ( new DatabaseDomain( $dbname, null, '' ) )->getId() ],
- [ 'dbFilePath' => $dbPath ]
+ [
+ 'dbFilePath' => $dbPath,
+ 'dbName' => 'do_not_select_me' // explodes if DB is selected
+ ]
);
$lb = $factory->getMainLB();
/** @var Database $db */
$db = $lb->getConnection( DB_MASTER, [], '' );
- $this->assertEquals(
- $wgDBname,
- $db->getDomainID()
- );
+ $this->assertEquals( '', $db->getDomainID(), "Null domain used" );
$this->assertEquals(
$this->quoteTable( $db, 'page' ),