Page 1 of 1

info from 2 databases

Posted: Wed May 23, 2007 3:53 pm
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?

Posted: Wed May 23, 2007 4:15 pm
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 

Posted: Wed May 23, 2007 4:16 pm
by thefreebielife
but where would i put the login info for the second db? (password etc.)

Posted: Wed May 23, 2007 4:18 pm
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.

Posted: Wed May 23, 2007 4:23 pm
by thefreebielife
2 db on one server. (example cash1 and freebie). but i have more then those two databases on the server

Posted: Wed May 23, 2007 4:27 pm
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.