Welcome Guest, Not a member yet? Register   Sign In
Using multiple databases with helper files
#1

[eluser]ryan656[/eluser]
I am writing an application that's using separate databases for scalability and I'm running into problems. I have helper files that interact with the databases and I use these helper files in multiple controllers. Here's an example of my problem.

I have a login controller that loads a 'user' database and calls a 'checkLogin' function contained in a helper file. It works fine when using one database, I load the database in the login controller with $this->load->database('dbusers') and in the helper file I can get the CI instance with $ci = &get;_instance() and then perform the query with $user = $ci->db->query("select statement").

The problem is when I try to use more than one database, the user guide says that to run multiple databases you write this:

$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

But when I try to do this I cannot get the code in the helper file to work cause it keeps coming back with an 'undefined' error.

This is what I tried to do: $dbusers = $this->load->database('dbusers', TRUE) in the login controller and then something like this in the helper file:

$ci = &get;_instance()
$user = $ci->dbusers->query("select statement")

I've also tried $user = $dbusers->query("select statement") but nothing seems to work.


I hope this makes sense and I know there's a way to do this in Codeigniter I just can't figure it out. Could the problem be I'm not using any models or that I'm loading the database in the controller and using it in the helper?

Any help would be greatly appreciated.


Thanks,
Ryan


Messages In This Thread
Using multiple databases with helper files - by El Forum - 12-06-2009, 01:41 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 01:49 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 02:04 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 02:09 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 02:12 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 02:29 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 02:37 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 02:49 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 02:57 AM
Using multiple databases with helper files - by El Forum - 12-06-2009, 03:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB