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());
}
}
}
ホスト マシン (localhost) で実行すると、$ipaddress
完全に動作します...リモート マシンで実行しようとしているので、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