How to check if a database is set up in settings.php? I am creating a module for Drupal 8. One of the requirements is that you first add a new database in settings.php. On the admin page, I want to check if the user did this step and show a warning if he didn't. I tried this:

global $databases;


But doing a var_dump shows nothing.

How do I access the databases variable so I can check if the database is setup?
global $databases has been removed in favor of the preexisting static connection info management methods on the Database class.

Drupal 7

global $databases;
// Check whether we have a default connection.
$has_connection = !empty($databases['default']['default']);


Drupal 8

use Drupal\Core\Database\Database;
$has_connection = (bool) Database::getConnectionInfo('default');


More links

https://www.drupal.org/node/2176621

https://www.drupal.org/node/1951216