PHP cannot connect to MySQL

Posted by yogal on Server Fault See other posts from Server Fault or by yogal
Published on 2010-03-01T20:42:50Z Indexed on 2010/04/23 16:54 UTC
Read the original article Hit count: 307

Filed under:
|
|
|
|

Hello,

I recently installed Apache 2 + PHP 5.3.1 + MySQL 5.1.44 on my Windows 7 64bit machine following this guide: http://sleeplessgeek.blogspot.com/2010/01/setting-up-apache-php-mysql-phpmyadmin.html

It all went fine, php is working great (even with XDebug) but I cannot connect to mysql server.

A simple script I wrote to test connection (yes, root has no pass):

    $username = "root";
    $password = "";
    $database = "test";
    $hostname = "localhost";

$conn = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL Database!!");

It prints this error after 60sec of timeout:

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.

I can connect to mysql using cmd>mysql -h localhost -u root

Services are working properly.


There also seems to be a problem with PhpMyAdmin (using 3.2.5). As soon as I type user and pass the page loads and turns blank (content-lenght in headers is 0 but status code is 302 Found). Looks like something wrong with cookies (my auth method).

I hope someone has a clue, it has to be something dumb simple I missed. Thanks in advance.

© Server Fault or respective owner

Related posts about php5

Related posts about mysql