View Full Version : switching databases on the fly

11-01-2008, 06:37 PM
I am using database 1 to insert user content. One of the table indexes for database 1 that holds the user content is the userid.

I then need to get the username and other user information which is stored in a different table in database 2. The user account table in database 2 also uses the userid as its index.

How can I access user information from table "users" in database 2 to if I am using the userid from table "user_content" in database 1?

SELECT username FROM database2_users WHERE userid = database1_user_content_userid

I realize the above is totally wrong.. but it summarize what I am trying to do.

Also, I assume I have to open a connection to both databases, right?

11-01-2008, 06:43 PM
SELECT username FROM database2.tableindatabase2name WHERE database2.tableindatabase2.userid = somenumber

You will have to populate the somenumber part.

Why are you using two databases anyways rather than just two tables?