Get mysql info in 2 different database

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
seontay
Forum Newbie
Posts: 6
Joined: Thu Aug 01, 2002 1:18 am

Get mysql info in 2 different database

Post by seontay »

I have a problem to retrieve a data from 2 different table in 2 different database. How to link it in single mysql query statement? Please help.

Thank you
Freddie
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

have a read of the second paragraph and code sample at this page: http://www.mysql.com/doc/en/USE.html
seontay
Forum Newbie
Posts: 6
Joined: Thu Aug 01, 2002 1:18 am

Post by seontay »

But in PHP we must link the 2 different database before perform the query. I try few times it still fail, How the correct statement look like? somebody please help. :(
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Depending on what exactly you want to do you could:
  1. use mysql_select_db() to select the first database, query that then use mysql_select_db() to switch to the second database so that you can query it, or
  2. use this type of syntax in your SQL statement (as shown in the page mydimension linked you to):

    Code: Select all

    SELECT author_name,editor_name FROM author,db2.editor WHERE author.editor_id = db2.editor.editor_id;
Mac
Post Reply