php访问远程数据库 [英] php access to remote database

查看:51
本文介绍了php访问远程数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助!

我在HOST1上有一个PHP(PHP 5.2.5)脚本,试图连接到MySql数据库HOST2.这两台主机都在通过CPanel控制的共享主机环境中.

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设置为允许来自HOST1的远程数据库连接.

HOST2 is set to allow remote database connections from HOST1.

我正在使用的PHP连接是:- $ h2 = IPADDRESS; $ dbu = DBUSER; $ dbp = DBPASS;

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

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

此操作始终失败:-

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

nb: SOMESTRING 似乎与共享主机环境有关.

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

任何想法?

顺便说一句:我可以使用OpenOffice通过ODBC和SQLyog从笔记本电脑建立到HOST2的远程连接. SQLyog和ODBC设置与PHP脚本尝试使用的设置完全相同.

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.

推荐答案

somestring可能是您的Web服务器的反向查找.

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

您可以从cPanel修改权限吗?您是否做了任何允许从工作站(ODBC)访问的操作?

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

错误消息似乎表明您可以通过网络访问mysql服务器,但没有来自该特定主机的用户名特权.

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数据库.* TO用户名@ ip.address.of.host1通过密码"标识

GRANT SELECT ON database.* TO username@ip.address.of.host1 IDENTIFIED BY 'password'

可能会为您工作.我只是在脑海中写下了这个,您可能要仔细检查mysql-docs中的语法.

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

这篇关于php访问远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆