Jump to content

mysql_connect: connection attempt failed


myrddinwylt

Recommended Posts

Hello,

 

Kind of a bizzare problem. From within PHP 5.3.2, if i try

 

mysql_connect("localhost","root","") or die(mysql_error());

 

It results in the following message:

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\server\websites\127.0.0.1\htdocs-ssl\cdrdownloader\index.php on line 23

Warning: mysql_connect() [function.mysql-connect]: 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:\server\websites\127.0.0.1\htdocs-ssl\cdrdownloader\index.php on line 23

Fatal error: Maximum execution time of 30 seconds exceeded in C:\server\websites\127.0.0.1\htdocs-ssl\cdrdownloader\index.php on line 23

 

If I try to connect on the same machine, but instead of using PHP, I use the command prompt (or quite literally connect in any other way except PHP), I connect with no problems:

 

C:\server\bin>mysql -P 3306 -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye

 

The "libmysql.dll" located in the PHP folder, is the same version for the server. What else am I missing ?  This only became a problem after updating (with a lot of effort), to PHP 5.3.2.  I kind of need to connect to MySQL using PHP

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/207202-mysql_connect-connection-attempt-failed/
Share on other sites

Figured out the problem

 

Apparently PHP 5.3.2 isn't smart enough to resolve "localhost" as "127.0.0.1" ... I put the IP in, and it works.  I tested this on an older version of PHP on the same machine, and the flaw was not present before 5.3.x.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.