$replicaDB = $this->getOption( 'replicadb', $this->getOption( 'slave', '' ) );
if ( $replicaDB === 'any' ) {
$index = DB_REPLICA;
- } elseif ( $replicaDB != '' ) {
+ } elseif ( $replicaDB !== '' ) {
$index = null;
$serverCount = $lb->getServerCount();
for ( $i = 0; $i < $serverCount; ++$i ) {
break;
}
}
- if ( $index === null ) {
+ if ( $index === null || $index === $lb->getWriterIndex() ) {
$this->fatalError( "No replica DB server configured with the name '$replicaDB'." );
}
} else {
$index = DB_MASTER;
}
- /** @var IDatabase $db DB handle for the appropriate cluster/wiki */
- $db = $lb->getConnection( $index, [], $wiki );
+ $db = $lb->getMaintenanceConnectionRef( $index, [], $wiki );
if ( $replicaDB != '' && $db->getLBInfo( 'master' ) !== null ) {
$this->fatalError( "The server selected ({$db->getServer()}) is not a replica DB." );
}
return $this->sqlPrintResult( $res, $db );
} catch ( DBQueryError $e ) {
if ( $dieOnError ) {
- $this->fatalError( $e );
+ $this->fatalError( (string)$e );
} else {
- $this->error( $e );
+ $this->error( (string)$e );
}
}
return null;