title: how to switch database in codeigniter
body: <p>i'm new to CI and i just wanna know is there a way to switch databases in CI,Eg:
  In login Page, there's a dropdown list that you can specify which database you wanna connect with, view look like this</p>
  
  <pre><code>&lt;select name="select" id="select"  &gt;
    &lt;option value="1"&gt;DB1&lt;/option&gt;                
    &lt;option value="2"&gt;DB2&lt;/option&gt;              
  &lt;/select&gt;
  </code></pre>
  
  <p>And i got 2 databases in database.php one is <code>default</code>the other is <code>local</code>
  by default i'm using the default one.</p>
  
  <p><code>$active_group = 'default';
       $active_record = TRUE;</code></p>
  
  <p>My question is how do i specify db based on the dropdown value, say if i pick DB1, connect to default one, DB2 goes to local one....
  I know how to swtich db manually by :</p>
  
  <pre><code> $this-&gt;load-&gt;database('default', TRUE); OR
   $this-&gt;load-&gt;database('local', TRUE);
  </code></pre>
  
  <p>Since i got different controller and model, how can i achieve this... i did try like:
  first get the value of dropdownlist in login function:</p>
  
  <pre><code>$this-&gt;load-&gt;model('My_Model');
  $db = $this-&gt;input-&gt;post('select')
  $this-&gt;My_Model-&gt;getDB($db);
  </code></pre>
  
  <p>and then in my model i got function :</p>
  
  <pre><code>function getDB($db)
  {
      if($db ==1)
      {
          $this-&gt;db  = $this-&gt;load-&gt;database('default', TRUE);
           }
      elseif($db ==2)
      {
          $this-&gt;db  = $this-&gt;load-&gt;database('local', TRUE);
      }
  }
  </code></pre>
  
  <p>Unfortunately,  it doesn't work..... Any help would be much Appreciated!!!!</p>