Bug #52434 [Bgs]: mysqlnd: host cannot be "localhost" when connecting to tcp port

From: Date: Sun, 25 Jul 2010 07:05:29 +0000
Subject: Bug #52434 [Bgs]: mysqlnd: host cannot be "localhost" when connecting to tcp port
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-152738@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52434&edit=1

 ID:               52434
 User updated by:  anthon dot pang at gmail dot com
 Reported by:      anthon dot pang at gmail dot com
-Summary:          mysqlnd: host cannot be a hostname
+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:

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";


Previous Comments:
------------------------------------------------------------------------
[2010-07-25 06:31:41] dtajchreber@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


Thread (12 messages)

« previous php.bugs (#152738) next »