info from 2 databases

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

info from 2 databases

Post by thefreebielife »

i would like to try this but don't even know where to begin?

does anyone have an example code that i can start off of?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

SELECT a.field_one, b.field_two FROM database_one.table_one a, database_two.table_two b WHERE a.user_name = 'blah' AND a.t_key=b.t_key ORDER BY a.field_one LIMIT 10 
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

but where would i put the login info for the second db? (password etc.)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Are you talking about two databases on 1 server or two databases on 2 different servers? In the latter case, you will need to use a separate database connection and multiple queries.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

2 db on one server. (example cash1 and freebie). but i have more then those two databases on the server
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

The user you logged into mysql with will need to have access permissions for both databases, you do not need to login/connect twice or create two database connections.
Post Reply