Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: not connecting to MySQL database  (Read 5015 times)

0 Members and 1 Guest are viewing this topic.

jcarterat

    Topic Starter


    Rookie

    not connecting to MySQL database
    « on: May 08, 2010, 09:11:39 AM »
    I am using 000webhost.com as my free and trial web hosting. When I try to connect to the database server, it says Access denied for the user@............

    (I have replaced the servername, userid and password with my actual and correct information)

    <?php
    $con = mysql_connect("server name","userid","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    echo "Connected to database";
    ?>

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: not connecting to MySQL database
    « Reply #1 on: May 08, 2010, 10:22:58 AM »
    Well if access is denied, it simply means you have a wrong username of password. The host/server is usually localhost - is this what you used?

    jcarterat

      Topic Starter


      Rookie

      Re: not connecting to MySQL database
      « Reply #2 on: May 08, 2010, 12:43:03 PM »
      no. 000webhost is telling me not to use 'localhost' and they give their own host name which I am using. But still not working.

      kpac

      • Web moderator
      • Moderator


      • Hacker

      • kpac®
      • Thanked: 184
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 7
      Re: not connecting to MySQL database
      « Reply #3 on: May 08, 2010, 04:57:02 PM »
      Try setting them as variables first.

      Code: [Select]
      <?php

      $host 
      "";
      $user "";
      $pass "";

      if(!
      $con mysql_connect($host$user$pass)
      {
        die(
      "Could not connect: " mysql_error());
      }

      ?>


      jcarterat

        Topic Starter


        Rookie

        Re: not connecting to MySQL database
        « Reply #4 on: May 08, 2010, 10:32:40 PM »
        Same error. No change :(

        kpac

        • Web moderator
        • Moderator


        • Hacker

        • kpac®
        • Thanked: 184
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 7
        Re: not connecting to MySQL database
        « Reply #5 on: May 09, 2010, 04:55:39 AM »
        Have you tried changing your username or password?

        jcarterat

          Topic Starter


          Rookie

          Re: not connecting to MySQL database
          « Reply #6 on: May 09, 2010, 07:00:03 AM »
          I did but it didn't work still :(

          kpac

          • Web moderator
          • Moderator


          • Hacker

          • kpac®
          • Thanked: 184
            • Yes
            • Yes
            • Yes
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: not connecting to MySQL database
          « Reply #7 on: May 09, 2010, 07:21:58 AM »
          I don't know so...

          Maybe you should try contacting them direct or try their forum.

          Bannana97



            Intermediate
          • Owner of HerbertsWorld Corporation
            Re: not connecting to MySQL database
            « Reply #8 on: May 09, 2010, 10:10:56 AM »
            This happens to everyone, and pretty much no one has fixed it, or got it to work.
            Thanks
            Bannana97

            jcarterat

              Topic Starter


              Rookie

              Re: not connecting to MySQL database
              « Reply #9 on: May 20, 2010, 12:32:28 AM »
              Please anybody reply... I am still facing same problem. Is there anyone who has confronted such problem and solved it ???

              kpac

              • Web moderator
              • Moderator


              • Hacker

              • kpac®
              • Thanked: 184
                • Yes
                • Yes
                • Yes
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 7
              Re: not connecting to MySQL database
              « Reply #10 on: May 20, 2010, 09:46:12 AM »
              Did you contact their support?

              jcarterat

                Topic Starter


                Rookie

                Re: not connecting to MySQL database
                « Reply #11 on: May 20, 2010, 01:06:03 PM »
                of course kpac. I have made every possible effort from my side. I contacted two hosting services, but neither could solve my problem. They just said that don't use "localhost" in place of hosting server name. I told them that I am already not doing that... Then they asked to contact some professional....

                Bukhari1986



                  Rookie

                  Thanked: 2
                  Re: not connecting to MySQL database
                  « Reply #12 on: May 29, 2010, 02:36:00 AM »
                  I am using the same 000webhost.com

                  I am using the below method and it works fine

                  <?PHP


                     mysql_connect("mysql123.000webhost.com", "a701646_dbusrname", "pass") or die(mysql_error());
                     echo "Connection to the server was successful!
                  ";

                     mysql_select_db("a701646_dbname") or die(mysql_error());
                     echo "Database was selected!

                  ";

                  $result = mysql_query("CREATE TABLE `users` (
                    `id` INT(11) NOT NULL AUTO_INCREMENT,
                    `name` VARCHAR(100) DEFAULT NULL,
                    `city` VARCHAR(100) DEFAULT NULL,
                    `web` VARCHAR(100) DEFAULT NULL,
                    `age` SMALLINT(6) DEFAULT NULL,
                    PRIMARY KEY  (`id`)
                  ) ENGINE=INNODB DEFAULT CHARSET=latin1");

                  echo $result;
                  ?>

                  jcarterat

                    Topic Starter


                    Rookie

                    Re: not connecting to MySQL database
                    « Reply #13 on: May 30, 2010, 07:04:54 AM »
                    Thank you very much Bukhari. It is working.

                    The difference I see here is that you are not assigning mysql_connect to a variable and directly doing it. Don't know whether this is a problem or what else?

                    Anyways, Thank you very much.

                    Bukhari1986



                      Rookie

                      Thanked: 2
                      Re: not connecting to MySQL database
                      « Reply #14 on: May 30, 2010, 02:54:11 PM »
                      mention not

                      welcome