Edit report at http://bugs.php.net/bug.php?id=52434&edit=1
ID: 52434 Updated by: johan...@php.net Reported by: anthon dot pang at gmail dot com Summary: mysqlnd: host cannot be "localhost" when connecting to tcp port Status: Bogus Type: Bug Package: MySQL related Operating System: Ubuntu 10.04 PHP Version: 5.3.3 New Comment: The patch won't be added as then "localhost" has two meanings - one time meaning "use the unixdomain socket in the default location" and one time actually "resolve localhost and use TCP" as it is taught in many places that "localhost" in MySQL has the first meaning we keep it there. Previous Comments: ------------------------------------------------------------------------ [2010-07-25 09:05:29] anthon dot pang at gmail dot com Seriously? http://www.php.net/manual/en/ref.pdo-mysql.connection.php gives two examples: mysql:host=localhost;port=3307;dbname=testdb mysql:unix_socket=/tmp/mysql.sock;dbname=testdb And my DSN (constructed by Zend Framework) follows the first example. Where does it say I have to define the unix socket in php.ini if I intend to connect using the tcp port? Here's the fix: --- mysqlnd.c.bak 2010-07-25 02:47:29.000000000 -0400 +++ mysqlnd.c 2010-07-25 02:49:37.000000000 -0400 @@ -635,7 +635,7 @@ char * transport = NULL; int transport_len; #ifndef PHP_WIN32 - if (host_len == sizeof("localhost") - 1 && !strncasecmp(host, "localhost", host_len)) { + if (!port && host_len == sizeof("localhost") - 1 && !strncasecmp(host, "localhost", host_len)) { DBG_INF_FMT("socket=%s", socket? socket:"n/a"); if (!socket) { socket = "/tmp/mysql.sock"; ------------------------------------------------------------------------ [2010-07-25 06:31:41] dtajchre...@php.net Tell PHP where your mysql.sock file is via the DSN or pdo_mysql.default_socket in the php.ini file and your error will go away. Your conclusion is way off. http://www.php.net/manual/en/ref.pdo-mysql.connection.php ------------------------------------------------------------------------ [2010-07-25 04:42:45] anthon dot pang at gmail dot com Description: ------------ With PDO_MYSQL, if PHP is linked with mysql client libraries (instead of mysqlnd), the DSN can contain a host parameter with a hostname, e.g., host=localhost. However, with mysqlnd, the host has to be an ip address, e.g., host=127.0.0.1. This occurs for '--with-mysqli=mysqlnd' or '--with-pdo-mysql=mysqlnd'. It appears mysqlnd wants to use a Unix socket even though the port is explictly specified, This backward incompatibility surprises users migrating from php 5.2.x and find their apps suddenly can't connect. MySQL 5.1.41 Test script: --------------- >From Zend Framework 1.10.6: $_isConnected = @mysqli_real_connect( $this->_connection, $this->_config['host'], $this->_config['username'], $this->_config['password'], $this->_config['dbname'], $port ); Expected result: ---------------- Expect it to connect. Actual result: -------------- Warning: PDO::__construct() [pdo.--construct]: [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in /var/www/libs/Zend/Db/Adapter/Pdo/Abstract.php on line 129 SQLSTATE[HY000] [2002] No such file or directory ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52434&edit=1