Welcome Guest, Not a member yet? Register   Sign In
One select statement that queries multiple databases
#1

[eluser]tinawina[/eluser]
Hi there - I'm in the planning stage for a project I need to get done that will add some new features to an existing website I coded with CI. I'm thinking it might be a good idea to set up a separate database for this new project since I'm already up to about 30 tables just for the website, and the project will add another 15-20 tables.

I understand that I can define as many databases as I want in the database config file. Seems very straightforward. But I don't understand how to do a query that stretches over 2 or more databases. If it were a non-CI situation I would do something like:

Code:
SELECT
database1.table.field, database2.table.field
FROM
database1.table, database2.table
WHERE
database1.table.another-field = database2.table2.another-field

CI has me setting up two discrete connections:

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

And then I'm calling the database like this, for eg.:

Code:
$DB1->query();
$DB1->result();
How would I do the SELECT statement described here given these discrete connections that you call one at a time? (Or am I just not getting this??) Any help is much appreciated. Thanks!


Messages In This Thread
One select statement that queries multiple databases - by El Forum - 05-05-2008, 12:11 PM
One select statement that queries multiple databases - by El Forum - 05-05-2008, 12:41 PM
One select statement that queries multiple databases - by El Forum - 05-05-2008, 12:53 PM
One select statement that queries multiple databases - by El Forum - 05-05-2008, 02:03 PM
One select statement that queries multiple databases - by El Forum - 05-05-2008, 02:15 PM
One select statement that queries multiple databases - by El Forum - 06-18-2009, 05:18 PM
One select statement that queries multiple databases - by El Forum - 06-18-2009, 05:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB