我有以下类,用于建立php
MySQL 连接($ipaddress
完全有效,仅用于隐藏实际 IP 地址)
class DbConn {
private $host;
private $user;
private $password;
private $database;
private $link;
private $db;
public function __construct($ipaddress) {
$this->host = $ipaddress;
$this->user = 'myuser';
$this->password = 'mypwd';
$this->database = 'mydb';
try {
$this->link = mysql_connect($this->host, $this->user, $this->password);
if (!$this->link) {
throw new Exception('Database connection error');
}
$this->db = mysql_select_db($this->database, $this->link);
if (!$this->db) {
throw new Exception('Cant use database: '. mysql_error());
}
} catch (Exception $e) {
print_r($e);
die('Could not connect: ' . mysql_error());
}
}
}
当我在$ipaddress
主机(localhost)上运行它时,它可以完美运行......现在我正在尝试在远程机器上运行它,这样我就可以远程连接到 MySQL 服务器。但是,我收到以下错误:
Warning: mysql_connect(): A connection attempt failed because the connected par
y did not properly respond after a period of time, or established connection fa
led because connected host has failed to respond.
in C:\performance\browser_perf\DbConn.php on line 18
我正在尝试连接的当前机器是一Windows 8 X86
台机器,并且 MySQL 服务器安装在一Windows 7 X64_86
台机器上。我有以下问题:
- 我是否还必须在远程服务器(
Win 8
)中安装 MySQL,或者php
接口可以为我处理该连接? - 我如何断言IP地址是正确的?我看着它使用
ipconfig