using link identifier with 2 DBs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

using link identifier with 2 DBs

Post by eskio »

Hi,

I my form I populate 2 list boxes from different 2 databases.To distinhuish them I use a link identifier in

Code: Select all

mysql_query($query, $link1)
and

Code: Select all

mysql_query($query, $link2)
.

Code: Select all

$link1 = @mysql_connect("localhost", "xxxx", "xxxxx");mysql_select_db("db1")
$link2 = @mysql_connect("localhost", "xxxx", "xxxxx");mysql_select_db("db2")
 
As you can see $link1 and $link2 are the same.

My question is to use a link identifer, the hostname of the databases should be different? because in the script refers only to the last opened database.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: using link identifier with 2 DBs

Post by Christopher »

eskio wrote:My question is to use a link identifer, the hostname of the databases should be different? because in the script refers only to the last opened database.
With MySQL a link is to a MySQL server which can contain many databases. You should select the database before each query.

Code: Select all

mysql_select_db("db1", $link);
mysql_query($query, $link)
(#10850)
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: using link identifier with 2 DBs

Post by eskio »

Thanks
Post Reply