Access to a db in other domain

I have 2 domains in my server. Each of domains have 1 mysql db: –> db1 –> db2

How can I connect to db2 from in php?
below code dose not work:
$conn = mysql_connect(‘localhost’,‘user_of_db2’,‘password’);

What is the error message you receive?

My issue was solved:

$conn = mysql_connect(‘IP ADDRESS’,‘user_of_db2’,‘password’);