Welcome Guest, Not a member yet? Register   Sign In
Can CodeIgniter query muiltiple disparate databases?
#1

[eluser]johnnyForums[/eluser]
I work in an organization with many different databases. They will never be one database. I cannot convert them so it's not an option. I need to be able to hit the different databases with my query, aggregate the data, put it in one seamless page. Can CodeIgniter do that? Can someone tell me how to query multiple databases? Thank you for any help.
#2

[eluser]Dam1an[/eluser]
There's a part in the user guide about connecting to multiple databases
#3

[eluser]johnnyForums[/eluser]
I actually saw that but wasn't sure how to put the results together in one page/view. I don't have much experience with CI an and evaluating several frameworks including RoR. How would I take these two connection, get some data, put them in the same view?
#4

[eluser]Thorpe Obazee[/eluser]
[quote author="johnnyForums" date="1247694403"]How would I take these two connection, get some data, put them in the same view?[/quote]

I am guessing, 'yes'.
#5

[eluser]Hakkam[/eluser]
[quote author="johnnyForums" date="1247694403"]I actually saw that but wasn't sure how to put the results together in one page/view. I don't have much experience with CI an and evaluating several frameworks including RoR. How would I take these two connection, get some data, put them in the same view?[/quote]

Yes ... you could also disconnect after save retrievedata in each db if be needed
#6

[eluser]Jedidiah Reeser[/eluser]
In reference to accessing multiple databases, my video tutorial might be able to help you.
Accessing Multiple Databases in CI -Jedidiah Reeser
#7

[eluser]dgreenhouse[/eluser]
[quote author="johnnyForums" date="1247690755"]I work in an organization with many different databases. They will never be one database. I cannot convert them so it's not an option. I need to be able to hit the different databases with my query, aggregate the data, put it in one seamless page. Can CodeIgniter do that? Can someone tell me how to query multiple databases? Thank you for any help.[/quote]

Hello,

I'm dealing with the same issue.

As I move forward, maybe some of my lessons may be of help.
Conversely, your research would be helpful to me also.

Here's the link to the thread I'm posting on now:
http://ellislab.com/forums/viewthread/124232/
#8

[eluser]dgreenhouse[/eluser]
Just looked at Jedidia's video and I it helped a lot.

http://jedidiahreeser.com/blog/2009/07/a...deigniter/
#9

[eluser]Jedidiah Reeser[/eluser]
I am glad the video tutorial on accessing multiple databases was helpful.

Thanks for the feedback!
#10

[eluser]Phil Sturgeon[/eluser]
If your MySQL user has permission to both databases, you can just prefix the table name with the database name.

Quote:SELECT * FROM db1.table1 t1
LEFT JOIN db2.table2 t2 ON t1.id = t2.fk_id

db1 & db2 are database names.

t1 & t2 are aliases so you dont need to keep writing the database and table names out in full.

I would assume you can do this with the ActiveRecord too.

Code:
$this->db->from('db1.table1 t1');
$this->db->join('db2.table2 t2', 't1.id = t2.fk_id', 'left');

Let me know how that works out. It should be much more efficient that running two queries and combining the results via PHP.




Theme © iAndrew 2016 - Forum software by © MyBB