Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
818 views
in Technique[技术] by (71.8m points)

mysql - php access to remote database

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...