Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found it very interesting your question and have been doing some research to solve your problem. I tell you my solution: the first is to activate the hooks, so in your config.php file make this change:</p> <pre><code>$config['enable_hooks'] = TRUE; </code></pre> <p>Once activated the hooks, you need to create a new hook, for it in the file config/hooks.php put something like the following:</p> <pre><code>$hook['post_controller_constructor'] = array( 'class' =&gt; 'DBTest', 'function' =&gt; 'index', 'filename' =&gt; 'dbtest.php', 'filepath' =&gt; 'hooks', 'params' =&gt; array(), ); </code></pre> <p>Thus, your hook kicks in once the controller has been instantiated, but has run no method yet. This is neccesary to use $CI = &amp;get_instance()</p> <p>To finish create the file /application/hooks/dbtest.php with content similar to the following:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class DBTest { function index() { $CI = &amp;get_instance(); $databases = array( 'mysqli://user1:pass1@host1/db1', 'mysqli://user2:pass2@host2/db2', 'mysqli://user3:pass3@host3/db3', 'mysqli://user4:pass4@host4/db4', 'mysqli://user5:pass5@host5/db5', ); foreach ($databases as $dsn) { $db_name = substr(strrchr($dsn, '/'), 1); $CI-&gt;load-&gt;database($dsn); $CI-&gt;load-&gt;dbutil(); if(!$CI-&gt;dbutil-&gt;database_exists($db_name)) { // if connection details incorrect show error show_error("Site is not available: can't connect to database $db_name"); } } } } </code></pre> <p>You must use dsn for $CI->load->database() in this way we can handle the error instead of Code Igniter when it tries to load the database.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload