近日因公司开发需要,在本机Win7下架设了Apache+MySql+PHP
所使用PHP版本:PHP5.3.0, 之后发现无法连接mysql数据库,均报超时错误:
PHP Warning: mysqli::mysqli(): [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in xxx.php on line x
PHP Warning: mysqli::mysqli(): (HY000/2002): 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 xxx.php on line x
在网站上查找了很久,均没有有效的解决办法.
后来在国外的网上查到此原因与windows的hosts文件有关
对如下进行修改:
# 127.0.0.1 localhost
#:: 1 localhost
修改为
127.0.0.1 localhost
#:: localhost
问题解决