php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50939 php_mysql.dll can't connect to "localhost" (::1) on Windows Vista
Submitted: 2010-02-05 16:38 UTC Modified: 2010-02-06 01:57 UTC
From: jpmasseria at yahoo dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.3.1 OS: Windows Vista
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jpmasseria at yahoo dot com
New email:
PHP Version: OS:

 

 [2010-02-05 16:38 UTC] jpmasseria at yahoo dot com
Description:
------------
PHP 5.3.1 is unable to connect to MYSQL running on same Windows Vista machine when host file contains:

::1         localhost   # IP v6 local host
127.0.0.1   localhost


If "::1" line is commented out, test program works.  This issue also affects phpMyAdmin.  This problem started after upgrading to PHP 5.3.1.

Running "mysql -h localhost" from command line works without issue.

When "::1" is commented out, phpMyAdmin says:

MySQL client version: mysqlnd 5.0.5-dev - 081106 - $Revision: 289630 $

Is this client embeded in php_mysql.dll?

Here is the verion of PHP I'm using:

C:\Users\johnma>php -v
PHP 5.3.1 (cli) (built: Nov 19 2009 10:17:43)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

Thank you,
John

Reproduce code:
---------------
<?php
echo "Hello there ...\n";

$dbhost = 'localhost';
$dbuser = 'xxx';
$dbpass = 'xxx';
$dbname = 'xxx';

echo "Attempting to connect to host=\"{$dbhost}\"\n";
$conn = mysqli_connect( $dbhost, $dbuser, $dbpass );

if( !$conn ) {
    printf( "Connect to mysqli failed: %s\n", mysqli_connect_error() );
    exit();
}

mysqli_select_db( $conn, $dbname );
$result = mysqli_query( $conn, "Select distinct date from statistics" );
if( !$result ) {
    echo mysqli_error( $conn );
    exit;
}

while( ($row = mysqli_fetch_assoc( $result )) != NULL ) {
    echo "\"{$row['date']}\" );\n";
}

exit();
?>


Expected result:
----------------
C:\Users\johnma>php -f test.php
Hello there ...
Attempting to connect to host="localhost"
"2009-04-01" );
"2009-04-02" );
"2009-04-03" );
"2009-04-04" );
"2009-04-05" );


Actual result:
--------------
C:\Users\johnma>php -f test.php
Hello there ...
Attempting to connect to host="localhost"
PHP Warning:  mysqli_connect(): [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in C:\Users\johnma\test.php on line 10
PHP Warning:  mysqli_connect(): (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 C:\Users\johnma\test.php on line 10
Connect to mysqli failed: 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-05 16:59 UTC] johannes@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

We can't really fix this issue without causing trouble in the future (MySQL 5.5 supports IPv6 so changing to use IPv4 only from PHP means that you're using IPv4 from PHP and IPv6 from the command line which gives a mess in regards to user rights)

Please use 127.0.0.1 as hostname, or configure your system not to use IPv6.
 [2010-02-06 01:10 UTC] jpmasseria at yahoo dot com
Thank you for your quick response on this.

What is the bug-id of the problem that this is a duplicate of?

Thank you,
John
 [2010-02-06 01:16 UTC] felipe@php.net
Bug #50172
 [2010-02-06 01:54 UTC] jpmasseria at yahoo dot com
Thanks, I see now, actually the original bug id is 45150, which goes on 
to explain that the issue involves PHP streams which doesn't recognize 
PHP streams.

Thanks again for the quick response.

John
 [2010-02-06 01:57 UTC] jpmasseria at yahoo dot com
Sorry, I meant to say PHP streams doesn't recognize IPv6 which is 
returned if localhost is resolved on Windows Vista if the host table 
contains the IPv6 entry ::1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC