本地系统Apache 2.2.14+PHP5.3.1+MySQL 5.0.22中,PHP5.3.1运行以下程序时无法连接MySQL 5.0.22
<?php
$link=mysql_connect("localhost","root","");
if(!$link) echo "失败!";
else echo "成功!";
mysql_close();
?>
出现以下错误:
Warning: mysql_connect() [function.mysql-connect]: [2002] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试 (trying to connect via tcp://localhost:3306) in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test3.php on line 2
Warning: mysql_connect() [function.mysql-connect]: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test3.php on line 2
Fatal error: Maximum execution time of 60 seconds exceeded in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test3.php on line 2
将程序中localhost改成127.0.0.1,如下:
<?php
$link=mysql_connect("127.0.0.1","root","");
if(!$link) echo "失败!";
else echo "成功!";
mysql_close();
?>