jjclarkson
jjclarkson

Reputation: 5954

Can you do queries against two databases if mysql_select_db was already used?

I have code that in the connection setup selects the database using mysql_select_db().

$link = mysql_connect('localhost', 'user', 'pass');
mysql_select_db("database1");

Can I later run a query against two databases such as:

SELECT database1.row, database2.row 
FROM database1.table, database2.table 
WHERE database1.row = database2.otherrow

even though "database1" was already selected at first? Or is there a method for unselecting the database?

Upvotes: 2

Views: 465

Answers (1)

Alix Axel
Alix Axel

Reputation: 154543

You can. Also check this out: How do I construct a cross database query in PHP?

Upvotes: 2

Related Questions