Welcome Guest, Not a member yet? Register   Sign In
postgres users authentication
#3

[eluser]Pascal Kriete[/eluser]
I assume you read the section on connecting to multiple databases here.

When you use the normal loading call, the database is attached to the CI super object as $db.
Code:
$this->load->database();  // no third parameter

// Use it:
$this->db->whatever();

But when you pass in that third parameter, the database object is returned instead of being tied to $db. So you would do:
Code:
$DB = this->load->database($dns, NULL, TRUE);

// Use it:
$DB->whatever();

If you need it for more than one method, you will want it as a class variable. Try this:
Code:
Class Categorias_model extends Model {
        /*
         * Table: categorias;
         * Fields:
         *     cat_codcategoria
         *     cat_nombre
         */    
        var $cat_nombre;
        
        function Categorias_model () {
            parent::Model();
            // Create a new connection
            $dns = $this->session->userdata('dns');
            print_r($dns);
            $this->DB1 = $this->load->database($dns, FALSE, TRUE);
        }
        
        function getCategoria($id) {
            $this->DB1->where("cat_codcategoria", $id);
            $query = $this->DB1->get("categorias");
            return $query->row();
        }
        
        function getCategorias() {
            $query = $this->DB1->get("categorias");
            return $query->result_array();
        }
}

Hope that helps.


Messages In This Thread
postgres users authentication - by El Forum - 11-09-2008, 01:22 AM
postgres users authentication - by El Forum - 11-09-2008, 03:06 PM
postgres users authentication - by El Forum - 11-09-2008, 05:27 PM
postgres users authentication - by El Forum - 11-09-2008, 09:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB