tags:

views:

1038

answers:

5

Help!

I have a PHP (PHP 5.2.5) script on HOST1 trying to connect to an MySql database HOST2. Both hosts are in Shared Host environments controlled through CPanel.

HOST2 is set to allow remote database connections from HOST1.

The PHP connect I'm using is:- $h2 = IPADDRESS; $dbu = DBUSER; $dbp = DBPASS;

$DBlink = mysql_connect($h2, $dbu, $dbp);

This always fails with:-

Access denied for user '<dbusername>'@'***SOMESTRING***' (using password: YES)

nb: SOMESTRING looks like it could be something to do with the shared host environment.

Any ideas???

BTW: I can make remote connections to HOST2 from my laptop using OpenOffice via ODBC, and SQLyog. The SQLyog and ODBC settings are exactly the same as the PHP script is trying to use.

+1  A: 

Just some ideas:

  • HOST1 does not have remote access to HOST2 (shared host is disallowing)
  • MySQL account does not have access from HOST1 (IP address specified on account creation, or wildcard)

Edit:

In response to your comment, I meant that HOST1 cannot get to the MySQL port on HOST2. Web services will work, of course, because port 80 is open to the public. As another user pointed out though, you are getting a response, so you are reaching it. I would try specifying the DB, and double checking the account creation command you ran.

For the second piece, I meant this: http://dev.mysql.com/doc/refman/5.0/en/adding-users.html

You can specify what host the username can connect from. If it isn't set to HOST2's IP or the wildcard, HOST2 can't log in with those credentials.

Abyss Knight
Thanks for the ideas - HOST1 can definately access HOST2, in fact I could solve the problem by simply setting up a mickeymouse webservice between the two - but I'd prefer to understand why this wont work :-)I don't know enough to understand your second idea.
GreybeardTheUnready
+2  A: 
  • Have you read the MySQL documentation on Causes of Access denied Errors?

  • Have you contacted support for your hosting provider? They should have access to troubleshoot the database connection. People on the internet do not have access.

  • Do you need to specify the database name? Your account might have access to connect only to a specific database. The mysql_connect() function does not allow you do specify the database, but new mysqli() does. I'm not sure if this is relevant -- it might allow you to connect but give you errors when you try to query tables that aren't in your database.

  • Are you sure you're using the right password? MySQL allows each account to have a different password per client host. Admittedly, this is not a common configuration, but it's possible. Your hosting provider should be able to tell you.

Bill Karwin
+4  A: 

somestring is probably the reverse-lookup for your web-server.

Can you modify privileges from your cPanel? Have you done anything to allow access from your workstation (ODBC)?

The error-message seems to indicate that you have network-access to the mysql-server, but not privileges for your username from that specific host.

If you're allowed to grant privileges for your database, invoking:

GRANT SELECT ON database.* TO [email protected] IDENTIFIED BY 'password'

might work for you. I just wrote this out of my head, you might want to doublecheck the syntax in mysql-docs.

jishi
Thanks - The clue was realising - as you pointed out - that the SOMESTRING was actually the reverse lookup of the actual web server that hosts my site.So I simply enabled remote access to that rather than the IP address of my website.... and all works.THANKS!
GreybeardTheUnready
A: 

The error message means that you can contact the mySql server, but the user you are trying to log in as, does not have access.

Either the user does not have access at all, or it has access locally, but not from the host you are connecting from.

gnud
A: 

You should try to use the hostname and port like $h2 = IPADDRESS:3307;