New to PHP and Databases

Discussion in 'Mac Programming' started by psharp, Jul 12, 2012.

  1. macrumors member

    Joined:
    Feb 18, 2011
    #1
    In an effort to learn something now that I'm done with school I decided to pick up PHP/MySQL. I use bluehost to host my portfolio but aside from that I feel like I'm not taking advantage of everything it has to offer. I ran into a nice snag when I tried to link PHP code to a database I created.

    I followed these steps setting up the database: https://my.bluehost.com/cgi/help/6
    Created a very simple 3 column table in the database.

    Stripped down my code and eventually used the code they suggested

    Code:
    <?php
    
    $dbh=mysql_connect ("localhost", "dbadmin", "********") 
         or die ('I cannot connect to the database.');
         mysql_select_db ("dbtest");
         echo "connected to the database";
    ?>
    
    Yet I continue to get this error:
    Code:
    [12-Jul-2012 02:11:04] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'dbadmin'@'localhost' (using password: YES) in /home6/sharpcgi/public_html/learning/action.php on line 3
    And can't for the life of me figure out the problem. It would be great if someone had advice or a solution.
     
  2. thread starter macrumors member

    Joined:
    Feb 18, 2011
    #2
    Figured it out. Yay for punching things until they work!
     
  3. macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    I was going to try and help. I started with php not to long ago and I also use bluehost but I have not created a db as of yet. But as I do get into db with bluehost was the problem on there end or a code bug on your end?
     
  4. macrumors regular

    Joined:
    Aug 12, 2008
    Location:
    Cambridge, UK
    #4
    At a guess I'd say the username was incorrect, looking at the Bluehost document it looks like they auto-add a prefix to the username that your create so probably something like my account_dbadmin rather than just dbadmin ;)
     

Share This Page