CodeIgniter Forums
Model won't connect to a different DB - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Model won't connect to a different DB (/showthread.php?tid=9315)



Model won't connect to a different DB - El Forum - 06-21-2008

[eluser]Unknown[/eluser]
Hey,
I have one database that is configured to autoconnect.
I have single model that has to connect to a different database.

For some reason though, the queries still return data from a table in the first database that has the the same name as a table in the second.

IE I want to get that "comments" table data from the second database, but instead I'm getting data from the first. What's wrong?

edit-
I've just noticed that if I remove the database model from the autoload config it works fine. Maybe I have to close the autoloaded database before loading the model with the new database? I tried using $this->db->close() but nogo.

My Controller file is this:

Code:
<?php
require_once('basecontroller.php');

class Geohashing extends BaseController {

    function Geohashing()
    {
        parent::Controller();            

        $geoDB['hostname'] = "localhost";
        $geoDB['username'] = "root";
        $geoDB['password'] = "";
        $geoDB['database'] = "geohashing";
        $geoDB['dbdriver'] = "mysql";
        $geoDB['dbprefix'] = "";
        $geoDB['active_r'] = TRUE;
        $geoDB['pconnect'] = TRUE;
        $geoDB['db_debug'] = FALSE;
        $geoDB['cache_on'] = FALSE;
        $geoDB['cachedir'] = "";
                        
        $this->load->model('geohashingdao','', $geoDB);
    }
    
    function index()
    {                                        
        $allcomments=$this->geohashingdao->db->get('comments')->result();
        $data['comments']=$allcomments;
        $this->load->view('geohashing/index', $data);
    }    
}