New to PHP and Databases

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

  1. psharp macrumors member

    Feb 18, 2011
    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:
    Created a very simple 3 column table in the database.

    Stripped down my code and eventually used the code they suggested

    $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:
    [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. psharp thread starter macrumors member

    Feb 18, 2011
    Figured it out. Yay for punching things until they work!
  3. larswik macrumors 68000

    Sep 8, 2006
    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. Ap0ks macrumors 6502

    Aug 12, 2008
    Cambridge, UK
    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