title: Codeigniter - multiple database connections
body: <p>I have a problem with multiple db connections at Codeigniter. At my database.php i configured two databases. </p>
  
  <pre><code>$active_group = 'cms';
  $active_record = FALSE;
       $db['cms']['hostname'] = 'localhost';
      $db['cms']['username'] = 'yoloo_cms';
      $db['cms']['password'] = 'password'; 
      $db['cms']['database'] = 'yoloo_cms'; 
      $db['cms']['dbdriver'] = 'mysql';
      $db['cms']['dbprefix'] = '';
      $db['cms']['pconnect'] = TRUE;
      $db['cms']['db_debug'] = TRUE;
      $db['cms']['cache_on'] = FALSE;
      $db['cms']['cachedir'] = '';
      $db['cms']['char_set'] = 'utf8';
      $db['cms']['dbcollat'] = 'utf8_general_ci';
      $db['cms']['swap_pre'] = '';
      $db['cms']['autoinit'] = TRUE;
      $db['cms']['stricton'] = FALSE;
  
      $db['hazeleger']['hostname'] = 'localhost';
      $db['hazeleger']['username'] = 'yoloo_websites';
      $db['hazeleger']['password'] = 'password2'; 
      $db['hazeleger']['database'] = 'yoloo_hazeleger'; 
      $db['hazeleger']['dbdriver'] = 'mysql';
      $db['hazeleger']['dbprefix'] = '';
      $db['hazeleger']['pconnect'] = TRUE;
      $db['hazeleger']['db_debug'] = TRUE;
      $db['hazeleger']['cache_on'] = FALSE;
      $db['hazeleger']['cachedir'] = '';
      $db['hazeleger']['char_set'] = 'utf8';
      $db['hazeleger']['dbcollat'] = 'utf8_general_ci';
      $db['hazeleger']['swap_pre'] = '';
      $db['hazeleger']['autoinit'] = TRUE;
      $db['hazeleger']['stricton'] = FALSE;
  </code></pre>
  
  <p>At my model i use this when i want to connect to a other db than the usual one: </p>
  
  <pre><code>function __construct()
  {
    parent::__construct();
    $this-&gt;load-&gt;database('hazeleger',TRUE);
  }
  </code></pre>
  
  <p>But at all time codeigniter connects to cms. When i remove</p>
  
  <pre><code>$active_group = 'cms';
  $active_record = FALSE;
  </code></pre>
  
  <p>Codeingiter gives an error. When i tried this</p>
  
  <pre><code>function __construct()
  {
    parent::__construct();
    $db2 = $this-&gt;load-&gt;database('hazeleger',TRUE);
  }
  
  function test()
  {
        $query  = "SELECT * FROM cms_modules";
        $result = $db2-&gt;db-&gt;query($query);
        return $db2-&gt;result();
  }
  </code></pre>
  
  <p>It gives an error. Variabele db2 does not exist. 
  I just want to choose, at every model, wich db i want to connect to.
  But is doesn,t work. Does somebody know, how i can work with different databases 
  at models.  </p>
  
  <p>Thank you very much!!</p>