PDA

View Full Version : Help! Nube Connecting PHP to SQL



dmossjr
04-11-2008, 02:33 PM
Hi all -

I'm just learning PHP/SQL, and have created a basic sql connect php script that looks like this:

<?php # Script 8.2) - mysqli_connect.php

DEFINE ('DB_USER', 'user name');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'databasename');

$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL:' . mysqli_connect_error() );

The script gives me an error like so:

Could not connect to MySQL:Access denied for user 'username'@'localhost' (using password: YES)

I created a database (the name I use on DB_NAME), and a user name and password which I also put in the fields above.

I've also tried using this format with the values: "sitename_user" and "sitename_password" as I noticed that's how they appear in the database view of the control panel.

Any advice on what's going wrong? Thanks!

charlesp
04-11-2008, 04:05 PM
user name is what you chose as a username preceded by your bluehost usernamme(usually the first eight characters of your domain name) followed by an _ example bhusername_dbusername. The same with the database name bhusername_dbname

It's not "sitename_password" it's just "password"

Did you set up the database in the control panel?

ssgc
04-11-2008, 08:41 PM
Did you assign the user privileges to the database?

-

motorcitydigital
04-10-2009, 01:41 PM
Please help, I've been stuck for hours!

I'm also not able to connect to my database. I have a mySQL database with a user defined and a userpassword assigned. For sake of conversation, let's say I have
domain: www.mydomain.com
user: testUser
pswd: passWrd

I get this error message:
Access denied for user 'testUser'@'box381.bluehost.com' (using password: YES)

Here's my sample code
<?php
mysql_connect("www.mydomain.com", "testUser", "passWrd") or die(mysql_error());
echo "Connected to MySQL<br />";
?>

areidmtm
04-10-2009, 03:27 PM
The host is localhost and the username should have the first 8 letters of the main domain before it. (The same username you use to log into cpanel)

Use something like this.



<?php
mysql_connect("localhost", "mydomain_testUser", "passWrd") or die(mysql_error());
echo "Connected to MySQL<br />";
?>

motorcitydigital
04-10-2009, 03:49 PM
The host is localhost


OH!!! That solves it! Thank you very much!