PDA

View Full Version : New to PHP and Databases




psharp
Jul 12, 2012, 03:21 AM
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


<?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:
[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.



psharp
Jul 12, 2012, 04:45 AM
Figured it out. Yay for punching things until they work!

larswik
Jul 12, 2012, 02:18 PM
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?

Ap0ks
Jul 12, 2012, 02:41 PM
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 ;)