Welcome Guest, Not a member yet? Register   Sign In
Dynamic database selection
#2

[eluser]WanWizard[/eluser]
You can load the database (this way) only once, after which it is assigned to $this->db. If you try to load another one, it detects it's already loaded, and returns false.

Secondly, if you try to load a database with a manual config, you need to pass all information in the array. If you want to reuse the default config, you have to load that first.

Try
Code:
// load the database config
include(APPPATH.'config/database'.EXT);

// get the default config
$config = $db['default'];

// override the database name
$config['database'] = "study_".$this->studycode;

// do not auto initialize the connection
$config['autoinit'] = FALSE;

// load the database driver
$db = $this->load->database($config, TRUE);

// and see if we can initialize it
if ( $db->initialize() ) {
    echo "true";
}
else
{
    echo "false";
}


Messages In This Thread
Dynamic database selection - by El Forum - 12-01-2010, 12:02 PM
Dynamic database selection - by El Forum - 12-01-2010, 12:31 PM
Dynamic database selection - by El Forum - 12-01-2010, 12:45 PM
Dynamic database selection - by El Forum - 12-01-2010, 03:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB