How can i use DB Connection of another site of my multisite? Following situation:
I have a multisite with several sites. The codebase is the same but every site has his own database. Now i'm creating a module where i want to make adjustments in the databases for all sites at the same time. So i have to be able to make database connections to the other sites.

I already was able to get the settings from the other sites with that:

$sites = glob(DRUPAL_ROOT . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);

foreach ($sites as $site) {
  $site_path = str_replace(DRUPAL_ROOT, '', $site);
  $siteName = str_replace('/sites/', '', $site_path);

  if (is_readable($site . '/settings.php')) {
    $siteConfigs[$siteName] = [];
    $settings = [];
    $databases = [];
    $app_root = DRUPAL_ROOT;

    require $site . '/settings.php';
    $siteConfigs[$siteName]['settings'] = new Settings($settings);
    $siteConfigs[$siteName]['databases'] = $databases;
  }
} ```


How can i use DB Connection of another site on my multisite installation? 
I tried different things like:

foreach ($siteConfigs as $siteConfig) {
  Database::addConnectionInfo('default', 'default', $siteConfig['databases']['default']['default']);
  $db = Database::getConnectionInfo();
  var_dump($db);

}


But it always returns just the current site.

Thanks for any advice!
You can initialize multiple database connections like this in your settings.php file:

&lt;?php
$databases['default']['default'] = array(
    'database' =&gt; 'sitedb1',
    'username' =&gt; 'admin',
    'password' =&gt; 'admin',
    'prefix' =&gt; '',
    'host' =&gt; 'localhost',
    'port' =&gt; '3306',
    'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' =&gt; 'mysql',
);

$databases['yellow-site']['default'] = array(
    'database' =&gt; 'sitedb2',
    'username' =&gt; 'admin',
    'password' =&gt; 'admin',
    'prefix' =&gt; '',
    'host' =&gt; 'localhost',
    'port' =&gt; '3306',
    'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' =&gt; 'mysql',
);

$databases['green-site']['default'] = array(
    'database' =&gt; 'sitedb3',
    'username' =&gt; 'admin',
    'password' =&gt; 'admin',
    'prefix' =&gt; '',
    'host' =&gt; 'localhost',
    'port' =&gt; '3306',
    'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' =&gt; 'mysql',
);


Then you can get the connections with your module etc.:

&lt;?php
$greenSiteDatabase = Database::getConnection('default', 'green-site');
$yellowSiteDatabase = Database::getConnection('default', 'yellow-site');
$defaultDatabase = Database::getConnection('default', 'default');


You can query a database like so:

$banana = $yellowSiteDatabase-&gt;select('SomeTable', 'st')
  -&gt;fields('st', ['fruit'])
  -&gt;condition('fruit', $someCode)
  -&gt;execute()
  -&gt;fetchObject();