Theoretically every "server" is on the net (whether intra- or inter-). The only way I could say for you to figure out if you're "live" or not is to use $SERVER['HTTP_HOST']. If you reach your localhost server via "localhost/something" then $SERVER['HTTP_HOST'] will be "localhost". Then when you access it via the internet, the $_SERVER['HTTP_HOST'] would be populated with something like "mysite.com" or "www.mysite.com".
So in your dbconnection.php file you could simply do:
<?php
$dbhost = ($_SERVER['HTTP_HOST'] == 'localhost' ? 'localhost' : 'mysql-1031.domain.net');
I'm guessing that you're probably hosted with Servage or some other cluster type of service where their MySQL servers are connected to like above.