Welcome Guest, Not a member yet? Register   Sign In
"$this->load->database('group_name')" doesn't work

I have another group than default in database config file, said 'test'. And I do this, $this->load->database('test'). It always use "default" group. I ddin't realise it until I deleted $active_group = "default", I got an error of invalid connection.

[eluser]Thorpe Obazee[/eluser]
try posting your controller. someone is bound to answer...

probably you should use this:

$db = $this->load->database('test',TRUE).


Thanka all. I tried '$db = $this->load->database(‘test’,TRUE)'. The same, it won't work! It always use active_group one. I think it's a bug.

Where are you trying to use the other database? Are you doing this in your config file or a separate controller class?

If it's a separate controller class, you can load a database by going
$DB1 = $this->load->database('group_one', TRUE);

Remember: group_one = the name of the first value you use when configuring the database values. So in that case you would go

$DB1 = $this->load->database('default', TRUE);

On database.php, I do ...

$active_group = 'default';
$db['default']['hostname'] = "xserver1";
$db['default']['username'] = "test1";
$db['default']['password'] = "postgres";
$db['default']['database'] = "testap";
$db['default']['dbdriver'] = "postgre";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "";
$db['default']['dbcollat'] = "";

$db['test']['hostname'] = "xserver1";
$db['test']['username'] = "test2";
$db['test']['password'] = "postgres";
$db['test']['database'] = "testap";
$db['test']['dbdriver'] = "postgre";
$db['test']['dbprefix'] = "";
$db['test']['pconnect'] = TRUE;
$db['test']['db_debug'] = TRUE;
$db['test']['cache_on'] = FALSE;
$db['test']['cachedir'] = "";
$db['test']['char_set'] = "";
$db['test']['dbcollat'] = "";

On autoload.php, I didn't load database.

On my controller, I do ...

It actually uses default group.
And I found if I delete "$active_group = 'default';", it cause an invalide database connection.

Does user test2 have sufficient access to your database?

Sure, test2 has sufficient access to database.

[eluser]The Wizard[/eluser]
sometimes php has a bug with open and closed db connections or maybe its a feature but in any case,
it doesn't behave like we want it to be. so simply use staffradio's method and it should work fine.

I'm having the same trouble.

Based on my login in needs to switch all database connections in my application to the new datbase connection, but calling

$this->load->database($domain, TRUE);

Isn't switching the database connection.


Theme © iAndrew 2016 - Forum software by © MyBB