Conditionally connect to mysql server in PHP

I’ve run into a problem that at my level of server-side programming (admittedly little) seems odd. I am running EasyPHP on my development computer, and the site I am managing is hosted by a hosting company (inmotion hosting). I am reworking some of the company’s databasing, and have the following problem connecting to MySQL.

I can connect to MySQL remotely, using www.myurl.org:3306 as the host. This works on MySQL workbench and php run on my development computer. However, this does not work when I run the script from the hosting server. Instead, I must use the string ‘localhost’.

First, can someone explain why the absolute URL doesn’t work when run on the server? Second, is there a single host I can put that would work on EasyPHP and on the hosting server? Third, if not, what would be the best way to conditionally connect using the URL or localhost, so that I do not have to keep changing the script depending on where it’ll be running. I tried

$con=mysql_connect("localhost", "$GLOBALS[username]","$GLOBALS[password]") or mysql_connect("http://www.myurl.org:3306", "$GLOBALS[username]","$GLOBALS[password]") or die(mysql_error()); 

thinking that if the first connect failed it would move on to the second, similar to how if it fails it moves on to the die(), but it doesn’t seem to work.