-1

我有以下类,用于建立phpMySQL 连接($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
4

3 回答 3

2

PHP 有一个客户端,它与服务器交互,你不需要在“客户端”机器上安装一个 MySQL 服务器。检查端口 3306 是否有响应。一个telnet IPofWin7MySQLServer 3306应该足够了

于 2013-08-14T18:52:54.743 回答
0

您需要只在目标机器上运行的 MYSQL Server (Win7)

于 2013-08-14T18:51:27.697 回答
0

在 MySQL 服务器上的 my.cnf 中,检查 bind-address 设置是否设置为 127.0.0.1。如果将其更改为 0.0.0.0。

于 2013-08-14T18:59:01.667 回答