Remotely connecting to a MySQL database

Solution 1:

Use the supplied domain name ukld.db.5510597.hostedresource.com

Prepending the hostname with an IP as you are doing only changes the hostname and that is why it is failing to connect.

The hostname will be converted to an IP address behind the scenes for you. No need to do it yourself. Plus, hardcoding IPs is bad practice as they can change over time.

Solution 2:

You need to use either the hostname or the IP address, not both.

If you have a command line MySQL client available to you, you can test your connection strings.

mysql -u myusername -p -h ukld.db.5510597.hostedresource.com -D testdb

It should then prompt you for your password. If it connects successfully transfer those settings to your PHP app!

Solution 3:

No need for IP address Try this

<?php
//Connect To Database
$hostname='ukld.db.5510597.hostedresource.com';
$username='myusername';
$password='mypassword';
$dbname='testdb';
$usertable='test';
$yourfield = 'lat';

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

$query = 'SELECT * FROM ' . $usertable;
$result = mysql_query($query);
if($result) {
    while($row = mysql_fetch_array($result)){
        print $name = $row[$yourfield];
        echo 'Name: ' . $name;
    }
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
?>

Solution 4:

You don't need to include the IP address