www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need Help Connecting To Database

Hybrid View

  1. #1
    Join Date
    Mar 2011
    Posts
    67

    Need Help Connecting To Database

    Hi everyone. I am unable to connect to my database I have set up. I have successfully connected to
    my mysql database many times. This is why I am so shocked and stumped that I can't connect. I am
    coding in php and I have checked all the common errors that I have had in the past - typos, forgot to list a variable, etc.

    Now, though, I swear I have the correct name, password and anything else that I can control from what I see,
    could someone suggest what I could do to start fixing this problem?


    Thanks.

    Here is what my webpage error reports:

    I am unable to connect to the database because of: Access denied for user 'myrealusername'@'localhost' (using password: YES)

    error_log:

    PHP Warning: mysql_connect(): Access denied for user 'myrealusername' (using password: YES) in /home3/path/to/public_html/directory/submit.php on line 50
    I put in parenthesis the 50th line in my code as it is referenced here.

    Here is my code:
    Code:
    <?php
    //  databaseConnect();
    
        if(isset($_POST['name'])){$name = $_POST['name'];}
        if(isset($_POST['email'])){$email = $_POST['email'];}
        if(isset($_POST['qor'])){$qor = $_POST['qor'];}
    
        $db_hostname = "localhost"; //Host
        $db_username = "username_here"; //Username
        $db_pass = "password_here"; //Password
        $db_name = "database_name"; //Database Name
    
        $dbc=mysql_connect($db_hostname, $db_username, $db_pass, $db_name) or die ('I am unable to connect to the database because of: ' . mysql_error());     //(Line 50)
        echo "connected to database" . "<br>";
    
       $dbselect = mysql_select_db("tablename", $dbc) or die ('I am unable to find that table because of: ' . mysql_error());
    Thanks for the help.

    Randy

  2. #2
    Join Date
    Feb 2011
    Posts
    231
    Hi,
    Try use this code:
    Code:
    $dbc=mysql_connect($db_hostname, $db_username, $db_pass) or die ('I am unable to connect to the database because of: ' . mysql_error());     //(Line 50)
        echo "connected to database" . "<br>";
    
    $dbselect = mysql_select_db($db_name, $dbc) or die ('I am unable to find that table because of: ' . mysql_error());
    The $db_name must be in mysql_select_db().
    Last edited by MarPlo; 12-27-2012 at 09:25 AM.

  3. #3
    Join Date
    Mar 2011
    Posts
    67
    Thanks for the suggestion, however, that didn't solve the connection problem. Any other ideas? thanks.

  4. #4
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    Access denied for user 'myrealusername'@'localhost' (using password: YES)

    try chaning localhost to 127.0.0.1

    They may appear to be the same in any other situation, but for MySQL they are very different. When you grant permissions, 127.0.0.1 is not the same host as "localhost". Give it a shot, this might be what's holding you up. It otherwise looks like OK code to me.

    Your issue is a mysql permissions/access issue, not really a PHP one. If you have "root" mysql user access, you should provide us the output of:
    SELECT user,host FROM mysql.user;
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles