views:

427

answers:

2

Hi All

I am attempting to connect to a remote MySQL server from my local machine virtualhost using the following code:

$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die(mysql_error());
        mysql_select_db($dbname, $conn) or die(mysql_error());

My problem is that I am unable to connect locally, receiving the error:

Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10060)

This is not the case when I upload the same PHP file to the server. I am able to query the database with no problems at all.

I am unable to connect via command line either, but I can access cPanel which rules out the chance of my IP being banned accidentally.

My local server is running PHP 5.2.9, the remote server 5.2.12

+3  A: 
  • firewall of the server must be set-up to enable incomming connections on port 3306
  • you must have a user in MySQL who is allowed to connect from % (any host) (see manual for details)

The current problem is the first one, but right after you resolve it you will likely get the second one.

Bozho
I created a wildcard user in remote MySQL when the problem first arose, thinking my IP may have changed (which it shouldn't have). I was able to connect to the same server a few days ago so I doubt it is a firewall issue.
BenTheDesigner
try telnet xx.xx.xx.xx 3306. If it doesn't connect, it's a network issue
Bozho
@Bozho: Unable to Telnet in on 3306. As it is shared server I'll have to speak to the host as I don't have access to their network.
BenTheDesigner
yes, that's the best thing to do.
Bozho
It's possible that the remote server is using a different port.
Jacob Relkin
Yes, it is. asl the host administrators about that, too
Bozho
@Jacob: MySQL can use whichever port it is configured to use, although in this case it is running on 3306 - I was able to connect to it last week, just seems to have died for some reason.
BenTheDesigner
Seems the problem was because of a change in firewall settings made at the hosts end. Accepting answer.
BenTheDesigner
A: 

is dbhost set to local then thats your problem

Grumpy
I did try to rule out the obvious before posting my problem on SO.
BenTheDesigner