Question: Can anyone help me to setup connection with multiple databases connection in Drupal 8? I have database on the same server and I want to access it along with default Drupal 8 database.

Answer: 
This is done in the same way as in Drupal 7: You can add the database credentials in your settings.php file.

```php
$databases['default']['default'] = array(
  'database' => 'drupal8',
  'username' => 'username',
  'password' => 'password',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

$databases['external']['default'] = array(
  'database' => 'external',
  'username' => 'username',
  'password' => 'password',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

```

You will now have two connection options, default and external. You can tell Drupal to use the *external* connection using `\Drupal\Core\Database\Database::setActiveConnection('external')` and switch back to the default one with `\Drupal\Core\Database\Database::setActiveConnection()` once you don't need anymore the *external* connection.
In addition to retrieving a database connection to the external database using [`Database::getConnection()`](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21Database.php/function/Database%3A%3AgetConnection/8.1.x), you can also use [dependency injection](https://www.drupal.org/node/2133171) in your code to retrieve the connection *as a dependency* and declare your connection in a module's services YAML file:

```
database.external:
  class: Drupal\Core\Database\Connection
  factory: 'Drupal\Core\Database\Database::getConnection'
  arguments: ['external']

external_database_dependent_service:
  class: Drupal\MODULE\Some\Class\For\A\ServiceUsingTheExternalDatabase
  arguments: ['@database.external']

```