connecting to a remote server that has a mysql database

Hi,

I have an issue where I get errors when I try to connect to a server that has the mysql database. I have tried using the IP address of the server with and without the port number and nothing is working; I still get an error.

This is my code:

<?php $dbhost = 'XX.XXX.XXX.XX'; // ip address of server // database connection info $dbuser = 'user'; $dbpass = 'pass'; $db = 'db'; $conn = mysql_connect( $dbhost, $dbuser, $dbpass ); mysql_select_db( $db ); if ( !$conn ) { echo "

" . "ERROR" . "

"; die( 'Could not connect: ' . mysql_error() ); } else { echo "

" . "WORKS" . "

"; } mysql_close( $conn ); ?>

This is the error and warnings that I get:

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://XX.XXX.XXX.XX:3306) in C:\wamp\www\test\includes\connection.php on line 11

//I know this warning is a timeout
Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\test\includes\connection.php on line 11

Could not connect: Access denied for user ‘’@‘localhost’ to database ‘db’

I am running on Wamp off of localhost. Could that be the problem? If it is how would you fix that?

This can be done quite easily. You just need to get an install of MySQL working correctly on server B, and specify in the permissions tables (in the mysql database) that connections from host A are to be allowed. Then, connect to host B from host A using a connect string that specifies the host to connect to is B. Check out all the MySQL docs on this (generally the best place to start anyway). Look at: Remote MySQL database tutorial

The SQL you’ll need to set up the right permissions will be something like:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> GRANT ALL PRIVILEGES ON *.* TO [email protected] IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

That’ll give you administrative priviliges as user phpuser on hostA over all databases (.) with password some_pass

Sponsor our Newsletter | Privacy Policy | Terms of Service