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

[eluser]datactrl[/eluser]
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.
#2

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

[eluser]mindprojects[/eluser]
probably you should use this:

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

;-)
#4

[eluser]datactrl[/eluser]
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.
#5

[eluser]stuffradio[/eluser]
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
Code:
$DB1 = $this->load->database('group_one', TRUE);
$DB1->query('yourqueryhere');

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

Code:
$DB1 = $this->load->database('default', TRUE);
$DB1->query('queryhere');
#6

[eluser]datactrl[/eluser]
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 ...
$this->load->database(‘test’);


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

[eluser]stuffradio[/eluser]
Does user test2 have sufficient access to your database?
#8

[eluser]datactrl[/eluser]
Sure, test2 has sufficient access to database.
#9

[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.
#10

[eluser]t0psub[/eluser]
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.

Thoughts




Theme © iAndrew 2016 - Forum software by © MyBB