Bug #24212 Localhost website cannot connect to MySQL via PHP
Submitted: 11 Nov 2006 9:42 Modified: 14 Mar 2008 20:35
Reporter: Roy DePhillip Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connectors: mysqlnd ( PHP ) Severity:S2 (Serious)
Version:5.0 OS:Any (Vista RC2)
Assigned to: Sveta Smirnova CPU Architecture:Any
Tags: vista

[11 Nov 2006 9:42] Roy DePhillip
Description:
With a webserver configuration on my Vista RC2 using Apache 2.2, PHP 5, and MySQL 5.0 I have found a small issue.  Setting up a default connection test php block It has proven to me that none of my PHP code will connect locally on my server.  The services are all running and the mysql_connect( host, logon, pass ) just won't connect.  I sent the code to a remote web server (Linux web server) and it connected just fine.  I also have setup my Suse Virtual PC with that same configuration as in my RC2 build and it connects fine.  At the moment I'm stuck transfering web applications into my Suse VPC to test each little chunk that I build.  I'm currently in email support with the Vista Developers who are trying to figure out just what needs to be done.  I believe its a security feature of Vista blocking the connection seeing as MySQL Admin and Query Browser have no issues connecting... Just php code requested from a browser.

How to repeat:
Install Vista RC2; Install Apache 2.2; Install PHP 5; Install MySQL 5.0; Ensure that all services are setup and running;

create an index.php in your document root;
use this PHP block (with your own database, logon, password, and table:
<?PHP
echo 'Connecting to OBMS Database...  ';
$link = mysql_connect( host, logon, password );
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
?>

obviously this is simply a debug block to see if i'm connecting and I don't even get through this Connection Successfully.  When you go to localhost/index.php the page will read:

Connecting to OBMS Database...  

but no connection.

Suggested fix:
Find the VISTA security feature that is blocking this connection (not in Firewall or Advanced Firewall settings... at least not obvious)
[1 Dec 2006 9:44] Sveta Smirnova
Thank you for the report.

But Vista is unsupported yet.

Also be sure problem is MySQL, not PHP + Apache + MySQL setup. This setup problem is met by users who use other Windows versions. For example, try to connect via mysql command line client.
[6 Mar 2007 8:09] Marco Del Percio
Yeah exactly same problem here but now Vista is out and my version is Vista Ultimate (Not RC1|2). It seems mysql_connect is locked it doesn't connect yet it doesn't fail though I can connect using mysql shell client or connect to other mysql servers. Tried adding Vista firewall exception but it's no use. Any ideas?

Marco Del Percio
[10 Apr 2007 7:41] Lukas Dadam
I've tried to connect to mysql via PHP in Vista Ultimate, but server didn't response. When I've tried to connect via other tool, e.g. Navicat, connecion is ok. 

I have a latest patch (MySQL and PHP). On bugs.php.net is posted, that it's isn't php bug.

Do anyone know, how to fix it?

Chosen
[12 Apr 2007 12:27] Sveta Smirnova
Thank you for the report and comments.

UAC in your case is turned on?
[16 Apr 2007 7:25] Sveta Smirnova
Lukas, PHP bug you mentioned is http://bugs.php.net/bug.php?id=39549?
[21 Apr 2007 10:36] Lukas Dadam
Dear Sveta,

I have UAC turned on. It's better to know, which program need the admin rules.

About the next comment. Problem posted on http://bugs.php.net/bug.php?id=39549? is not acctually problem of mine. Because there is described problem on Vista RC2 and I have Vista final. 
I had properly installed Apache2, PHP 5.2.1 and MySQL 5.0.37, by the same technique as on XP, but when I've tried to connect to mysql via php in Vista, server responce was, that I'm calling undeffined function.

In short, this line is causing error (not the connection header):
$DBS=mysql_connect("http://localhost", "root", "");

Thanks for help
[23 Apr 2007 9:22] Sveta Smirnova
Thank you for the report.

Verified as described in the initial post. UAC doesn't matter. Extension mysqli doesn't work with cli too.
[23 Apr 2007 9:39] Sveta Smirnova
With PHP4 and PHP6 cli both extensions mysql and mysqli work.
[30 May 2007 19:23] Vladan Zajda
One possible sollution is to copy "libmySQL.dll" from "mysql/bin/" to "vista/system32/". Need to restart Apache, no need to restart Vista.
Hope this helps someone.
[31 May 2007 17:28] Sveta Smirnova
With today PHP snapshots bug is only repeatable with mysqlnd.
[2 Jun 2007 3:52] Jim Winstead
Give this a category that is more appropriate (even if still not quite right).
[4 Feb 2008 23:30] Sveta Smirnova
There is similar bug #34264
[6 Mar 2008 16:43] Andrey Hristov
The dump is ok. What about a dump for localhost? On windows it will be still 127.0.0.1 via TCP
[14 Mar 2008 20:35] Sveta Smirnova
Bug is not repeatable with current verison of mysqlnd. Please upgrade.
[15 Apr 2008 13:43] Paul Gathogo
What is the status of this bug?
[31 Mar 2010 20:22] Steve Reeves
I am having a similar problem. It worked fine up until I uninstalled PHP, APACHE, and MYSQL. Once I reloaded everything, the system wouldn't let MYSQL responses back to the browser.
[19 Apr 2010 21:56] Michael Garcia
This is a common problem in Vista. I took me hours to find the solution.

Either change the "localhost" in your php script to "127.0.0.1" to connect to MySQL 

or

Comment the "::1  localhost" 

There is no proper solution for this problem yet, but at least that will do
http://bugs.php.net/bug.php?id=45150