Here is stupid "optimization":
If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters.
(c) MySQL docs
So to guarantee correct result in the case of different databases on same server you need to do mysql_select_db() before every query or to use new_link parameter in .ini file if you can.