title: Codeigniter - Using Multiple Databases
body: <p><strong>database.php</strong>:</p>
  
  <pre><code>$db['default']['hostname'] = "192.168.2.104";
  $db['default']['username'] = "webuser";
  $db['default']['password'] = "----";
  $db['default']['database'] = "vad";
  $db['default']['dbdriver'] = "mysql";
  $db['default']['dbprefix'] = "";
  $db['default']['pconnect'] = TRUE;
  $db['default']['db_debug'] = TRUE;
  $db['default']['cache_on'] = FALSE;
  $db['default']['cachedir'] = "";
  $db['default']['char_set'] = "utf8";
  $db['default']['dbcollat'] = "utf8_general_ci";
  
  $db['stats']['hostname'] = "192.168.2.104";
  $db['stats']['username'] = "webuser";
  $db['stats']['password'] = "---";
  $db['stats']['database'] = "vad_stats";
  $db['stats']['dbdriver'] = "mysql";
  $db['stats']['dbprefix'] = "";
  $db['stats']['pconnect'] = TRUE;
  $db['stats']['db_debug'] = TRUE;
  $db['stats']['cache_on'] = FALSE;
  $db['stats']['cachedir'] = "";
  $db['stats']['char_set'] = "utf8";
  $db['stats']['dbcollat'] = "utf8_general_ci";
  </code></pre>
  
  <p>The issue is I can only define in the configuration one 
  <code>$active_group</code>, default, or stats. I followed the CodeIgniter documentation and I added the following:</p>
  
  <pre><code>$DB2 = $this-&gt;load-&gt;database('stats', TRUE);
  </code></pre>
  
  <p>This way I connect to the second database, but I lose the connection to the first one. Does anyone have any ideas on how can I load the two database without having to do the following in all models constructors?</p>
  
  <pre><code>$database1 = $this-&gt;load-&gt;database('database1', TRUE);
  $database2 = $this-&gt;load-&gt;database('database2', TRUE); 
  </code></pre>
  
  <p>Regards,</p>
  
  <p>Pedro</p>