...

View Full Version : Can't connect to database on localhost :S



martynball
08-21-2011, 10:01 PM
Hey, I have got a website in my documents folder (C:\inetpub\wwwroot) and i'm trying to connect to a database. But i'm getting an error saything that I can't :S



Error: 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.




$host = "localhost";
$username = "martynball";
$password = "password";

$con = mysql_connect($host, $username, $password);
if (!$con) { echo "<br /> Error: ". mysql_error(); }


Any ideas?

Fou-Lu
08-21-2011, 10:07 PM
Is MySQL running and listening on default port 3306?

martynball
08-21-2011, 10:11 PM
I believe so as I have not changed anything, and i'm running a Minecraft server with a plugin which writes to the database. And the config is using the same login information ect, and it has created some tables ect..



mysql:
hawkeye-table: hawkeye
port: 3306
player-table: hawk_players
username: martynball
world-table: hawk_worlds
hostname: localhost
max-connections: 10
password: password
database: minecraft

Fou-Lu
08-21-2011, 10:13 PM
I believe so as I have not changed anything, and i'm running a Minecraft server with a plugin which writes to the database. And the config is using the same login information ect, and it has created some tables ect..



mysql:
hawkeye-table: hawkeye
port: 3306
player-table: hawk_players
username: martynball
world-table: hawk_worlds
hostname: localhost
max-connections: 10
password: password
database: minecraft


Did this come from the CLI interface or from something like PHPMyAdmin?

martynball
08-21-2011, 10:16 PM
Did this come from the CLI interface or from something like PHPMyAdmin?

That's from a config file which the server uses. Also the minecraft server is located in appdata

Fou-Lu
08-21-2011, 10:19 PM
Change your $host in the first code to '127.0.0.1:3306'. Does that work?

martynball
08-21-2011, 10:26 PM
Awesome thanks, that works. Could you explain explain to me what that IP is? And why localhost wouldnt work? If you can, I like to know these things :P

Fou-Lu
08-21-2011, 10:33 PM
127.0.0.1 is a loopback address referring to your machine. I have no idea why they allocated an entire class A network address for it :/. :3306 says to use port 3306.
Open your file: C:\Windows\System32\Drivers\etc and double click the hosts (no extension) and open with notepad. I'm betting there is an entry in there that appears as # 127.0.0.1 localhost. If that hash sign is there, remove it and resave the hosts file. It will then map 'localhost' lookup to 127.0.0.1.

martynball
08-21-2011, 10:49 PM
Ah yeah it is there. Thanks.

Can't save the file though as it is being used :(

Fou-Lu
08-21-2011, 11:09 PM
Ah yeah it is there. Thanks.

Can't save the file though as it is being used :(

Lol. It'll be your browser I'd bet.
Save it another time. All that matters it that 'localhost' is only mapped to 127.0.0.1. If its going to a different address, that would be a very big problem.


Oh yeah, btw you'll need to actually open notepad as administrator and then open the hosts; I'd expect anything below Windows to require administrative authority. UAC FTL.

martynball
08-21-2011, 11:30 PM
Ah okay thanks, and yeah. it is very annoying lol



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum