title: How to Connect to database CI from login
body: <p>How do I connect to a database using form login, so the username and password will be stored from login form.  I don't want to setup a default username and password in <strong>database.php</strong>; it should be derived from the user login form.</p>
  
  <p>This is my model </p>
  
  <pre><code>function connect(){
          $nik=$this-&gt;input-&gt;post('nik');
          $password=$this-&gt;input-&gt;post('password');
  
      $config['hostname'] = 'localhost';
      $config['username'] = $nik;
      $config['password'] = $password;
      $config['database'] = 'test';
      $config['dbdriver'] = 'postgre';
      $config['dbprefix'] = '';
      $config['pconnect'] = TRUE;
      $config['db_debug'] = TRUE;
      $config['cache_on'] = FALSE;
      $config['cachedir'] = '';
      $config['char_set'] = 'utf8';
      $config['dbcollat'] = 'utf8_general_ci';
      $config['swap_pre'] = '';
      $config['autoinit'] = TRUE;
      $config['stricton'] = FALSE;
      $config['port']=5432;
      //$_SESSION['conn'] = $db;  
      $dbo= $this-&gt;load-&gt;database($config,TRUE);  
      //redirect('user/index');
  
  
   //end connecting
  </code></pre>
  
  <p>This my controller.</p>
  
  <pre><code>        function login(){
          $this-&gt;load-&gt;model("databaseconnection");
          $this-&gt;databaseconnection-&gt;connect();
          $dbo= $this-&gt;load-&gt;database($config,TRUE);  
          if (!$dbo) {
                      echo "not";
              }else{ 
                  echo "ok";
  
                  }
                              }
  </code></pre>
  
  <p>So I want to access database to controller, but still error. very need your helps</p>