Edit report at https://bugs.php.net/bug.php?id=60315&edit=1
ID: 60315 Updated by: [email protected] Reported by: jacob at frende dot me Summary: mysql_error: "connection actively refused" when no database info is supplied -Status: Open +Status: Bogus Type: Bug Package: MySQL related Operating System: Windows Server 2008 PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Historic behavior. Don't use mysql_* functions for new stuff. Use mysqli or PDO. Previous Comments: ------------------------------------------------------------------------ [2011-11-18 16:14:32] anon at anon dot anon >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." ------------------------------------------------------------------------ [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
