Web Analytics Made Easy -
StatCounter Can't connect to database on localhost :S - CodingForum

Announcement

Collapse
No announcement yet.

Can't connect to database on localhost :S

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Is MySQL running and listening on default port 3306?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      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

      Comment


      • #4
        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?
        PHP Code:
        header('HTTP/1.1 420 Enhance Your Calm'); 
        Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

        Comment


        • #5
          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

          Comment


          • #6
            Change your $host in the first code to '127.0.0.1:3306'. Does that work?
            PHP Code:
            header('HTTP/1.1 420 Enhance Your Calm'); 
            Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

            Comment


            • #7
              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

              Comment


              • #8
                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.
                PHP Code:
                header('HTTP/1.1 420 Enhance Your Calm'); 
                Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                Comment


                • #9
                  Ah yeah it is there. Thanks.

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

                  Comment


                  • #10
                    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.
                    PHP Code:
                    header('HTTP/1.1 420 Enhance Your Calm'); 
                    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                    Comment


                    • #11
                      Ah okay thanks, and yeah. it is very annoying lol

                      Comment

                      Working...
                      X