A connection attempt failed

I’ve just installed PHP on my IIS webserver with MySQL. When I try to execute the following code I get an “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. (2002)” error.

$db = new mysqli(‘127.0.0.1’, ‘user’, ‘password’, ‘database’);

if ($db->connect_errno > 0) {
echo “Failed to connect to MySQL: (” . $db->connect_errno . ") " . $db->connect_error;

}

I’ve tried chaning the IP to localhost, I’ve added ::1 to hosts file, I’ve setup a user on MySQL for ‘user’@‘127.0.01’, I’ve tried the original mysql_connect command, I’ve tried PDO commands, all to no avail.
I can login to the MySQL server locally with CLI and the database is accessed remotely with no connection issues. The problem is only seen via PHP.

Any other suggestions would be greatly appreciated.

IIS 7.5
PHP 5.3.28
MySQL 5.0

phpinfo;

mysqli
MysqlI Support enabled

Client API library version mysqlnd 5.0.8-dev - 20102224 - $Id: 731e5b87ba42146a687c29995d2dfd8b4e40b325 $
Active Persistent Links 0
Inactive Persistent Links 0
Active Links 0

Directive Local Value Master Value

mysqli.allow_local_infile On On
mysqli.allow_persistent On On
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.max_persistent Unlimited Unlimited
mysqli.reconnect Off Off

Try localhost, inplace of the IP:

[php]$db = new mysqli(‘locaclhost’, ‘user’, ‘password’, ‘database’);[/php]

Thanks for the response but I’ve tried that as well as adding port number and checked that the port number is set correctly.

sorry, missed that. I don’t use PHP on IIS for a few reasons, this being one of them… All I can suggest is this, http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-mysql-for-php-applications-on-iis-7-and-above

I have seen that article and while it is a recommendation to have the MySQL and IIS on separate servers to “avoid resource contentions between the database and Web server processes” it doesn’t suggest that it shouldn’t work at all. While I’m in the design phase this is just a test bed I’ve setup to test the code and should work. Very frustrating.

[member=69011]Topcoder[/member] does a lot of MS stuff, he may know.

[member=72272]astonecipher[/member] Thanks for mentioning me, I don’t read all the messages, mainly the ones no one replies too.

[member=75920]brarb[/member] Make sure you comment out the ipv6 address in your host file… the # sign is a comment. So your host file will have the two lines below

[php]127.0.0.1 localhost

::1 localhost[/php]

If the above doesn’t work, Then check the windows firewall for the MySQL firewall rules (They get installed with MySQL)

Are you using 2008 r2? or Windows 7?

I’d tried it with and without the IPv6 entry and neither had an effect but the IPv6 entry is commented out. It’s running on W7

You can go over these two articles…

https://bugs.php.net/bug.php?id=45150
http://blogs.iis.net/donraman/archive/2010/06/11/php-5-3-and-mysql-connectivity-problem.aspx

I don’t have the problem you’re experiencing, but I also use 2008 R2, not win 7.

I also think I disabled IPv6 on my Nic and maybe disabled it in my registry too.

http://support.microsoft.com/kb/929852

Thanks for the info. I did run the handy debug script in the article;

$httpfile = file_get_contents(“http://127.0.0.1/foo.txt”);
print “File contents read using 127.0.0.1: \n\n” . $httpfile . “\n\n”;
$httpfile = file_get_contents(“http://localhost/foo.txt”);
print “File contents read using localhost: \n\n” . $httpfile . “\n\n”;

and neither of the commands generated the connection attempt failed error, so it would seem the localhost issue is not what is happening here.

That then lead me to check my firewall for which I use Comodo and found one checkbox labeled “Filter Loopback Traffic”, unchecked it and works perfectly. Thanks for all your help.

Sponsor our Newsletter | Privacy Policy | Terms of Service