Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Can't connect to database on localhost :S

    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

    Code:
    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.
    Code:
    $host = "localhost";
    $username = "martynball";
    $password = "password";
    
    $con = mysql_connect($host, $username, $password);
    if (!$con) { echo "<br /> Error: ". mysql_error(); }
    Any ideas?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Is MySQL running and listening on default port 3306?

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    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..

    Code:
    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

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by martynball View Post
    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..

    Code:
    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?

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    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

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Change your $host in the first code to '127.0.0.1:3306'. Does that work?

  • Users who have thanked Fou-Lu for this post:

    martynball (08-21-2011)

  • #7
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    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

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • Users who have thanked Fou-Lu for this post:

    martynball (08-21-2011)

  • #9
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Ah yeah it is there. Thanks.

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

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by martynball View Post
    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.

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

  • Users who have thanked Fou-Lu for this post:

    martynball (08-21-2011)

  • #11
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Ah okay thanks, and yeah. it is very annoying lol


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •