Welcome Guest, Not a member yet? Register   Sign In
CI2 - multiple database bug
#1

[eluser]ripken204[/eluser]
This person is having the same issue as me, so read it as well:
http://www.phpfreaks.com/forums/applicat...deigniter/

I am trying to connect to databases in the constructor of models.
My two models are below.
The Account class you will notice has print_r($this->DB2) right before I perform the query, this shows the correct information.
The odd thing is that it throws the error

Quote:Table 'teams2010.accounts' doesn't exist
SELECT * FROM accounts WHERE id='1'
Filename: application/models/account.php

This is the database name for my Teams class, im not sure how it even knows about that, especially since the line before where i print out the DB info, it says the database is the Users database.

In my controller, if i dont load the Teams model, it works fine.
If i load only my Teams model and not my Account model, it works fine.

So obviously something is messed up here, I am not sure what could be wrong with my code..
It's as if CI2 does not use the information that is in my database resource, but instead is using the last connected database's information.

This is for accessing user accounts
Code:
class Account extends CI_Model {

    // The table storing user accounts
    var $table = 'accounts';
    private $DB2 = NULL;

    function __construct() {
        parent::__construct();
        $this->DB2 = $this->load->database('admin', TRUE);
    }
    

    function get($id) {
        echo "<br><br><br>";
        print_r($this->DB2);
        echo "<br><br><br>";

        $query = $this->DB2->query("SELECT * FROM $this->table WHERE id='$id'");
        
        if ($query->num_rows() === 1) {
            return $query->row();
        }
        
        return NULL;
    }
}


This does nothing yet
Code:
class Teams extends CI_Model {

    private $DB1;

    function __construct() {
        parent::__construct();
        $this->DB1 = $this->load->database('teams', TRUE);
    }
}


Messages In This Thread
CI2 - multiple database bug - by El Forum - 02-05-2011, 01:36 PM
CI2 - multiple database bug - by El Forum - 02-05-2011, 01:51 PM
CI2 - multiple database bug - by El Forum - 02-06-2011, 09:41 AM
CI2 - multiple database bug - by El Forum - 02-06-2011, 11:51 AM
CI2 - multiple database bug - by El Forum - 02-06-2011, 11:53 AM
CI2 - multiple database bug - by El Forum - 05-30-2011, 11:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB