php (error?) how to connet to a remote mysql?

Status
Not open for further replies.

hlmaster

New Member
Messages
9
Reaction score
0
Points
0
I ahve a universal mysql DB that im using for a game (hl - tfc) and it has 'stats' in it, I have php files to 'red the stats' and I want to know if its possible to connect to a remote mysql.. it is timing out with
Code:
Warning:  mysql_connect() [[URL="http://hlm.exofire.net/stats/function.mysql-connect"]function.mysql-connect[/URL]]: Can't connect to MySQL server on '76.73.77.53' (4) in /home/hlm/public_html/stats/index.php on line 3
Unable to select database

so, I want to know if its possible to do this.. I can also do DNS if need be..

any help?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
In order to connect to a remote MySQL server, it has to make a network connection. This means:
  1. There has to be a network path between the two. This will be true for any computers on the internet, but not isolated networks.
  2. The MySQL server has to be listening on a TCP port, and
  3. the client has to connect to this port, and
  4. there can't be any firewalls blocking the communication.
On X10, for instance, 2 (and probably 4) are false.

The default MySQL port is 3306. If the server is listening on a different port, you have to specify it when you create the connection. You can run `telnet host 3306` from a command line as a quick test to see if the server is listening on port 3306 and is open to the outside. Of course, this won't tell you if the X10 computer can reach the remote MySQL server.

Assuming there's no network issue, the client has to provide a MySQL username and password. You did well to provide the error, but without a minimal test case, it's extremely difficult to say what's going wrong. Should you post code, you should (of course) replace any user credentials with (e.g. "mysql_connect('server6.besthostingco.com', $dbUser, $dbPassword)".

Also, strongly consider using PDO instead of the old MySQL driver. For one thing, PDO supports prepared statements. Otherwise you need to worry more about SQL injection.

Running `telnet 76.73.77.53 3306` from my computer connected and started a handshake from MySQL 5.0.81, so it looks like 76.73.77.53 does have a MySQL server listening on that port. This doesn't rule out the possibility of connection problems between X10 and 76.73.77.53.

As for using DNS, it won't help with the error you're getting. All DNS would do is turn a name like server6.besthostingco.com into an address like 76.73.77.53. Of course, should the server change its IP address in the future, using a domain name means you wouldn't have to update your code.
 
Status
Not open for further replies.
Top