I have codeigniter configured to use multiple databases. For some customers, we need to query an additional database so this is a matter of:
if( isConfigured(database) )
foo();
However, the attempts I have made have either given the same result whether or not the db is configured in databases.php
, or throws an error.
I have attempted the following:
if( $this->load->database('optional') == FALSE )
Which raises the error You have specified an invalid database connection group
try( $this->load->database('optional') )
{
foo();
}
catch(Exception $e)
{
doNothing();
}
Which raises the same error
The documentation states that $this->load->database('optional', TRUE)
returns the connection ID however I cannot check this as the code errors out before returning a value.
I was expecting to be able to check whether or not a property had been set, e.g. $this->config->item('db')['optional']
but this would be largely guesswork to determine how to access the correct property
I have also looked into the dbutil
class but this only applies to databases which have already established a connection.