Access to a db in other domain

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

How can I connect to db2 from mysite1.com 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’);