I've never done it before, but mysql_query() takes an optional second parameter which is a resource identifier. You could use this param to specify which DB you are connecting to. Eg.
// get link identifiers
$dbh1 = mysql_connect....
$dbh2 = mysql_connect...
// use these link IDs when selecting your DBs
// and pass link ID to each query so query uses the correct DB
$result1 = mysql_query("some query", $dbh1);
$result2 = mysql_query("some query", $dbh2);
You said you were using classes so you could set the link ID in your constructor and use it in all of your queries.
Hope this helps!