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

Categories

0 votes
926 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...