you just have to create to connection, one for each database.
ex:
$conn=mysql_connect("database1","user","pass"

;
$conn2=mysql_connect("database2","user2","pass2"

;
then, as you need to query one databse or the other, you just use the correct connection
$res=mysql_exec($conn,"select * from table;"

;
if selecting in 1st DB
or
$res=mysql_exec($conn2,"select * from table;"

;
if selecting in 2nd DB Khaldryck
Programmer at the University of Brussel (Belgium)