#logo
PHOTO   GUESTBOOK
好久没玩这东西了。
看了下上次备份下来的,PHP5.1.x,MySQL5.0.x,还是个Dev版本。
直接去抓了最新的发布版,升到Apache/2.2.15 (Win32) +PHP/5.3.2(Win32 VC6)+MySQL5.1.47(Win32),OS是Win7(x86)。

配置web服务器不是一次两次了,不过这次版本跨度有点大,还是看了下各个官方的升级说明。
Apache和MySQL变化不大,倒是这个PHP5.3.x以后变化有点大。
首先是Access的方式变化,



引用官方说明就是,
MySQL也为PHP6专门设计了一个native driver,称为mysqlnd,这是一个采用PHP开源协议(即 PHP license)的MySQL数据库驱动,避免了任何可能存在的版权问题,所以PHP开发者可以放心大胆地使用。

mysqlnd成为php 5.3中的默认mysql驱动,它有如下优点:
解决了版权隐患问题,如上所述;由于版权问题,PHP5中没有默认支持MySQL,不像以前的PHP4那样可以直接使用MySQL函数。Mysql支持还需要把libmysql.dll复制到windows目录,然后修改php.ini等等,比较麻烦。
功能改进、效率提高,包括优化过的数据库持久化连接,这非常重要;
mysqlnd编译安装更简单,因为它是php源码树的一个组成部分;
Mysqlnd目前只支持PHP6,将来会支持PHP5,因为PHP5的接受程度一直在稳定上升,特别是很多PHP开发框架如Zend Framework等的渐渐普及,将带动PHP5的普及;
mysqlnd和php内部机制结合更紧密,是优化过的mysql驱动;
mysqlnd更节省内存,从测试结果来看,比传统的mysql扩展节省40%的内存;
mysqlnd更快;
mysqlnd提供了丰富的性能统计功能;
这个改动应同时对mysql和pdo_mysql扩展生效。
看上去不错,而且不用像以前那样把一堆文件复制到 \Widnows\System32下面了。

可这次装完,问题来了。
Warning: mysql_connect() [function.mysql-connect]: [2002] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试 (trying to connect via tcp://localhost:3306) in D:\www\index.php on line 9 ”
经Console连接测试,确认了MySQL安装正确,而且HTTPD+PHP的环境在没有MySQL连接的情况下工作正常。

先看了下MySQL和PHP文档的相关说明,
The error (2002) Can't connect to ... normally means that thereis no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

PHP manual says the following on mysql_connect:

Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as Runtime Configuration in your PHP configuration and leave the server field blank.

接下来做了下Google作业,确认出现的问题是否是因为这个原因导致的。搜索关键字是"PHP5.3 MySQL 错误"还有"PHP5.3 MySQL error 2002"。
看来碰到和我一样问题的人还不少,基本上都是Win7上配置的人。
根据说明和其他人碰到的问题的描述,试了下将localhost改成127.0.0.1访问就可以了。看来是localhost的解释问题。
打开hosts文件一看,Win7下对localhost 127.0.0.1一行是被注释掉的...
将注释删掉,再用localhost访问,OK~
2010/05/23 18:34 2010/05/23 18:34
#fist posted at 2010/05/23 18:34
No Trackback, No Comment

trackback url (click to copy):
http://fist.allosoft.com/tc/trackback/45