Can anyone please help me on how to check if secondary database is set. If not throw an error.
I am currently defining database connection as below.
Database::getConnection('default', 'sqlite')
I am trying to defining a if , else condition based the database defining.
When I try
if(Database::getConnection('default', 'sqlite')){ echo success; }else { echo fail; }
I am getting below error. If secondary database definitinot defined in settings.php
DrupalCoreEntityEntityStorageException: The specified database connection is not defined: sqlite in DrupalCoreEntitySqlSqlContentEntityStorage->save() (line 811 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).