A) You want to access two databases from the same php code?
There is nothing special about. Whatever mysql interface you choose in php (old one, MySQLi, PDO_MySQL), you get a context resource or an object you can (have to) use in all your future activities related to that database connection.
or
B) You want to have sql query involving two different databases?
Well, that does not involve php directly, but the database engine. Look around here:
http://dev.mysql.com/doc/refman/5.1/en/federated-storage-engine.html[
^],
http://winashwin.wordpress.com/2012/08/22/mysql-federated-table/[
^]