Page 1 of 1

Connecting to a DB on a different server than the PHP file

Posted: Tue Nov 07, 2006 1:30 pm
by impulse()
I have wrote a PHP script that connects to a MySQL server on another IP address but it trying to connect to localhost still. The script is as follows:

Code: Select all

mysql_connect("x", "x", "x");
mysql_select_db("x");

$query = mysql_query("SELECT * FROM x");

while ($results = mysql_fetch_array($query)) {
  echo $results['id'], "<br>";
  echo $results['fName'], "<br>";
  echo $results['sName'], "<br>";
  }
But I receive the following error:
PHP Warning: mysql_connect(): Access denied for user 'database'@'stesbox.co.uk' (using password: YES) in /var/www/html/php/test/db.php on line 3
Stesbox.co.uk is my own box that the PHP file is running on. Can someone advise my of what I've done wrong here please?

Regards,

Posted: Tue Nov 07, 2006 1:33 pm
by Luke
sorry for the dumb question, but did you enter in the new host instead of "localhost"

Posted: Tue Nov 07, 2006 1:42 pm
by impulse()
Yeah. Sorry, removing the host wasn't a good idea for my post.

I can telnet to the IP on port 3306 fine so the MySQL connection is there but my script seems to want to connect to localhost

Posted: Tue Nov 07, 2006 1:54 pm
by impulse()
Sorry, ignore my post below, not solved :(

Solved.

If I put the connection strings in ' ' rather than " " it connects fine.[/b]

Posted: Tue Nov 07, 2006 2:03 pm
by volka
You had a $ in your password?
(can't imagine another reason)

Posted: Tue Nov 07, 2006 2:07 pm
by impulse()
Nope, the password is a plain ole string.

I tried using ' ' instead of " " just as a test. I've even tried setting the server address as the reverse DNS entry to the IP of the server but still without any connection success. Would someone mind trying my script on a server and let me know the results please?

Posted: Tue Nov 07, 2006 2:10 pm
by volka
Access denied for user 'database'@'stesbox.co.uk' (using password: YES)
The actual connection to the server is working but your credentials are rejected.
see http://dev.mysql.com/doc/refman/5.0/en/ ... enied.html

Posted: Tue Nov 07, 2006 2:13 pm
by impulse()
A-ha! It works.

My mistake is that when I was receiving
Access denied for user 'database'@'stesbox.co.uk' (using password: YES)
It looks to me like it was my server (stesbox.co.uk) that was rejecting the password.