I create 2 connectionsand then try to select the current active database:

$aaa_link = mysql_connect("host1","user1","pass1") or die(mysql_error());
$bbb_link = mysql_connect("host2","user2","pass2")or die(mysql_error());
 
mysql_select_db("dbname1", $aaa_link) or die(mysql_error());

However, mysql_select_db fails with error:

Access denied for user: "user2" to database "dbname1"

What is wrong here?

Sorry, mistake - host1 = host2, but users, passwords and dbnames there are different. By the way the next code worked perfectly:
$aaa_link = mysql_connect("host1","user1","pass1") or die(mysql_error());
mysql_select_db("dbname1", $aaa_link) or die(mysql_error());
That is the bbb_link's line that caused this problem for some reason. It appears as if after the second mysql_connect the mysql tries to work on the $bbb_link database and ignores the existence of $aaa_link.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.