【发布时间】:2013-06-12 14:58:49
【问题描述】:
我突然明白了:
Warning: mysql_connect(): in C:\xampp\htdocs\login.php on line 12
cannot connect to server 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.
我使用这个代码:
$dbhost="localhost";
$dbusername="dbusername";
$dbpassword="dbpassword";
$db_name="database";
mysql_connect("$dbhost", "$dbusername", "$dbpassword") or die("cannot connect to server". mysql_error());
mysql_select_db("$db_name") or die("cannot select db". mysql_error());
将主机更改为:
$dbhost="127.0.0.1";
一切都恢复正常了。
为什么会这样?我怎样才能修复它像以前一样工作? 谢谢!
【问题讨论】:
-
我打赌它是一个 Windows 环境,很可能安装了 WAMP,而且您的主机文件中没有提到
localhost。
标签: php mysql database-connection localhost mysql-connect