0

I'm getting a connection timed out when I try to connect to an external (not on the same server as this code is on) database through the following code. I know the settings of the database is set up right, and the login info is good, 'cause I can login fine from my computer with HeidiSQL. If anyone can see a problem with this code, thanks.

function database_connect(){
$link = @mysql_connect("xx.xxx.xxx.xx:3306","root","pass"); 
$sql_error = mysql_error();

if (!$link) { 
    echo "Connection with the database couldn't be made.<br>";
    echo "$sql_error"; 
    exit;
}

if (!@mysql_select_db("databasename")) {
    echo "The database couldn't be selected.";
    exit;
}
return $link;
}
database_connect();
Deniz Zoeteman
  • 9,691
  • 26
  • 70
  • 97

2 Answers2

1

have you tried adding the IP address of where that script is hosted to "Remote Database Access Hosts"? If you're on cPanel, you need to allow the IP address who can remotely access the datase(mysql). If you're not, then this is just an idea of what to do.

user1732887
  • 288
  • 1
  • 2
  • 9
1

Problem known now.

My webhost does not allow connections to an external database.

Deniz Zoeteman
  • 9,691
  • 26
  • 70
  • 97