Codeigniter - Check if a database connection has been configured
<p>I have codeigniter configured to use multiple databases. For some customers, we need to query an additional database so this is a matter of:</p>

<pre><code>if( isConfigured(database) )
    foo();
</code></pre>

<p>However, the attempts I have made have either given the same result whether or not the db is configured in <code>databases.php</code>, or throws an error.</p>

<p>I have attempted the following:</p>

<pre><code>if( $this-&gt;load-&gt;database('optional') == FALSE )
</code></pre>

<p>Which raises the error <code>You have specified an invalid database connection group</code></p>

<pre><code>try( $this-&gt;load-&gt;database('optional') )
{
    foo();
}
catch(Exception $e)
{
     doNothing();
}
</code></pre>

<p>Which raises the same error</p>

<p>The documentation states that <code>$this-&gt;load-&gt;database('optional', TRUE)</code> returns the connection ID however I cannot check this as the code errors out before returning a value.</p>

<p>I was expecting to be able to check whether or not a property had been set, e.g. <code>$this-&gt;config-&gt;item('db')['optional']</code> but this would be largely guesswork to determine how to access the correct property</p>

<p>I have also looked into the <code>dbutil</code> class but this only applies to databases which have already established a connection.</p>