Bug #60315 [Com]: mysql_error: "connection actively refused" when no database info is supplied

From: Date: Fri, 18 Nov 2011 16:14:32 +0000
Subject: Bug #60315 [Com]: mysql_error: "connection actively refused" when no database info is supplied
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-165335@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60315&edit=1 ID: 60315 Comment by: anon at anon dot anon Reported by: jacob at frende dot me Summary: mysql_error: "connection actively refused" when no database info is supplied Status: Open Type: Bug Package: MySQL related Operating System: Windows Server 2008 PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: >This leads one to believe invalid credentials have been supplied or that the specified account >is not configured (Host=) as expected. That's what happens. The behavior of mysql_query if a connection has not been opened is (for some reason) to call mysql_connect() with no arguments to try and establish one first. And when mysql_connect is not given arguments, it uses the server settings in php.ini, and if that's not configured, it will just try to connect to localhost:3306 with the process username and an empty password. In your case, the preconfigured mysql_connect values aren't pointing at a valid server and/or port, so the TCP/IP connection fails, and mysql_query fails in turn. That error message is not generated by PHP; it comes from the underlying Windows sockets library. See the text for WSAECONNREFUSED: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681391%28v=vs.85%29.aspx#wsaeconnrefused PHP couldn't replace the message completely without losing potentially valuable information on the details of the problem, but I guess they could chain error messages to make it more descriptive. E.g., "mysql_query could not issue the query because a database connection was not established and mysql_connect failed with the following error: Attempted to connect to localhost:3306 but received the following error from the system: No connection could be made because the target machine actively refused it." Previous Comments: ------------------------------------------------------------------------ [2011-11-16 22:51:14] jacob at frende dot me Description: ------------ If no connection currently exists and mysql_query is run without specifying connection info, mysql_error returns: "No connection could be made because the target machine actively refused it." This is not true. This is heinously deceptive: • "target machine" indicates a database server. • "actively refused" means a server RECEIVED the request AND DENIED it. This leads one to believe invalid credentials have been supplied or that the specified account is not configured (Host=) as expected. The error message should be changed to reflect the fact that no database connection (or connection information) exists. (this is especially troublesome when working with PDO coupled with a function since functions are only aware of the variables that are passed to them) Test script: --------------- <?php mysql_query("SELECT * FROM database.table;") or die(mysql_error()); ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60315&edit=1

« previous php.bugs (#165335) next »