我试图连接到我的外部SQL数据库,但我不断收到此错误:
mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\zconnect.php on line 10
Unable to connect to database! Please try again later.
这是PHP脚本:
<?php
$hostname='111.11.111.11'; #this is not my real ip address
$username='root';
$password='password';
$dbname='database';
$usertable='users';
$yourfield = 'admin';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$query = 'SELECT * FROM ' . $usertable;
$result = mysql_query($query);
if($result) {
while($row = mysql_fetch_array($result)){
print $name = $row[$yourfield];
echo 'Name: ' . $name;
}
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
?>
试过这个,但也不起作用:
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.1.14/"
# to give access to phpmyadmin from outside
# replace the lines
#
# Require local
#
# by
#
# Require all granted
#
感谢任何帮助!
答案 0 :(得分:1)
首先,我建议你的远程MySQL服务器SSH服务器和TCPing-ing或Netcat-ing(好吧,我停止),所以你看看它是否真的可以被访问。一些主机 - 主要是共享 - 要求你先让它们启用远程MySQL(有些主机在CPanel上有这个选项)。
其次,一些MySQL服务器将某些客户端列入白名单,以便自行访问。 phpMyAdmin可以帮助您阅读和设置此配置。