PDA

View Full Version : Can't connect to MySQL server on 'localhost' (10061)


umen242
02-15-2008, 09:23 AM
Hello all
first i like to say that i was searching all google to find answer but with no lock.
i installed apache 2.2 + mysql 5 + php 5.2 on win2k
i changed the mysql port to be 3307 and also changed the parameter in the php.ini mysqli.default_port = 3307
mySql is running fine , im doing telnet localhost 3307 and getting connected .
i added the php/ext/extras into the path


now i like to test the connection from apache php to mysql but getting this error :
Fri Feb 15 09:55:32 2008] [error] [client 127.0.0.1] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on 'localhost' (10061) in H:\\Apache2.2\\htdocs\\dbtest.php on line 9

my php code looks like this :
<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';
// username and password to log onto db server
$dbUser='root';
$dbPass='root';
// name of database
$dbName='test';
$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
print "Connected successfully<br>";
mysql_close($link);
?>

why im getting this error all the time?

rangana
02-15-2008, 09:27 AM
It should be like this:
<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';
// username and password to log onto db server
$dbUser='root';
$dbPass='password';
// name of database
$dbName='test';
$link = mysql_connect($dbServer, $dbUser, $dbPass) or die("Could not connect");
print "Connected successfully<br>";
mysql_close($link);
?>

You should not quote it, because it will be treated as string.
See if it helps :D

CFMaBiSmAd
02-15-2008, 10:16 AM
rangana, the double-quotes around the variables are not the problem. The variables will be parsed inside of double-quotes. The only consequence of the double-quotes is it takes a few more microseconds for the code to be parsed and executed.

umen242, you stated you changed mysqli.default_port = 3307 but you are not using mysqli_connect(). You need to change mysql.default_port = 3307 to go with the mysql_connect() or more simply, just include the port number in your connection information -

$dbServer='localhost:3307';

rangana
02-15-2008, 10:24 AM
Owsh?!..I did'nt thought of it!..I just tried it in my PC and it work, except for changing the default port :D