使用PHP连接到远程MySQL服务器 [英] Connecting to remote MySQL server using PHP

查看:381
本文介绍了使用PHP连接到远程MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码从本地计算机virtualhost连接到远程MySQL服务器:

I am attempting to connect to a remote MySQL server from my local machine virtualhost using the following code:

$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die(mysql_error());
        mysql_select_db($dbname, $conn) or die(mysql_error());

我的问题是我无法在本地连接,收到错误消息:

My problem is that I am unable to connect locally, receiving the error:

无法连接到"xxx.xxx.xxx.xxx"(10060)上的MySQL服务器

Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10060)

当我将相同的PHP文件上传到服务器时,情况并非如此.我能够毫无问题地查询数据库.

This is not the case when I upload the same PHP file to the server. I am able to query the database with no problems at all.

我也无法通过命令行进行连接,但是我可以访问cPanel,这排除了我的IP被意外禁止的可能性.

I am unable to connect via command line either, but I can access cPanel which rules out the chance of my IP being banned accidentally.

我的本​​地服务器正在运行PHP 5.2.9,远程服务器是5.2.12

My local server is running PHP 5.2.9, the remote server 5.2.12

推荐答案

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