Welcome Guest, Not a member yet? Register   Sign In
Calling $this->load->database() multiple times
#7

[eluser]WanWizard[/eluser]
I don't have my data distributed over lots of databases, so I don't have this issue.

If you can come up with a standard for naming your database objects, you could manually assign them to the CI superobject:
Code:
//User Model:
get_user_by_uid($uid) {
    $user = $this->get_cached_user($uid);
    if ($user === False) {
        $sql = 'SELECT * FROM user WHERE uid = ?';
        if ( ! isset($this->CI->udb) )
        {
            $this->CI->udb = $this->load->database('user', TRUE);
        }
        $user = $this->CI->udb->query($sql, array($uid))->row_array();
    }
    return $user;
}
You can extend the Model library, and have the constructor of MY_Model create the $this->CI variable.

Alternatively you can extend the Loader class, and create your version of the database() method.

You have to figure out a way to determine if a config is already loaded. One way of doing that is to use the config name in the CI variable. Currently, $this->db is created hardcoded. You could change this so that this is the behaviour for 'default', while p.e. loading the database with the 'user' config creates $this->db_user. Then in the database() method you could check if the object already exists, and only intantiate it if it doesn't.


Messages In This Thread
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 12:56 PM
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 01:30 PM
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 01:33 PM
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 03:08 PM
Calling $this->load->database() multiple times - by El Forum - 06-08-2010, 01:08 AM
Calling $this->load->database() multiple times - by El Forum - 06-08-2010, 01:24 AM
Calling $this->load->database() multiple times - by El Forum - 06-08-2010, 06:45 AM
Calling $this->load->database() multiple times - by El Forum - 06-23-2010, 03:04 AM
Calling $this->load->database() multiple times - by El Forum - 06-23-2010, 03:35 AM
Calling $this->load->database() multiple times - by El Forum - 06-23-2010, 03:59 AM
Calling $this->load->database() multiple times - by El Forum - 01-12-2011, 04:13 PM
Calling $this->load->database() multiple times - by El Forum - 01-12-2011, 04:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB