php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60315 mysql_error: "connection actively refused" when no database info is supplied
Submitted: 2011-11-16 22:51 UTC Modified: 2011-11-20 16:38 UTC
From: jacob at frende dot me Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.3.8 OS: Windows Server 2008
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jacob at frende dot me
New email:
PHP Version: OS:

 

 [2011-11-16 22:51 UTC] 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());
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-18 16:14 UTC] 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-20 16:38 UTC] johannes@php.net
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.
 [2011-11-20 16:38 UTC] johannes@php.net
-Status: Open +Status: Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC