PDA

View Full Version : Mysql connection mystery



bluehostuserguy
03-16-2008, 11:30 AM
I am moving from one hosting company to Bluehost, and did an apparently successful import of a database. I can use Bluehost's phpMyAdmin to navigate through the database.

My page uses PHP to connect to it, using the format:

@mysql_connect($database,$username,$password);
@mysql_select_db($database) or die( "Please try back later.");

If I use "echo $database;" "echo $username;" and "echo $password;" just prior to those lines, it appears that I've got the right password, right username, and right database...and this all works just fine on the old website (I haven't transferred the nameservers yet...I want to get it working properly on Bluehost first.)

But I'm getting a "Please try back later" every time.

Does anyone know what's going on? I'm on the Bluehost temporary URL...do I need to provide more info, such as a full directory path? (The database is in an addon directory)

Has anyone else had this issue? I'm totally stumped. It seems like it should just...connect...poof...but that's not what's happening. Any help would be great. Thanks very much.

charlesp
03-16-2008, 12:27 PM
Your username and database name are prefixed with your bluehost username and a (_). Your bluehost username is in the cPanel and is usually the first eight letters of your domain name

example: database username = bhuser_dbusername

database name = bhuser_dbname

That should do it.:D

redsox9
03-16-2008, 01:10 PM
Actually, in the mysql_connect request, it should be


mysql_connect($hostname,$username,$password)

$hostname should be "localhost"

Then, in the mysql_select_db request, it should be


mysql_select_db($bhuser_database)

Basil
03-17-2008, 03:24 PM
@ will supress any errors. If you're debugging this I suggest removing that.

You can also explicitely tell the script to output an error with mysql_error() (http://php.net/mysql_error).

Redsox is correct in pointing out that mysql_connect should have the server as its first value, and of course doesn't take the database name at all. That's the whole reason for mysql_select_db.

messels
05-08-2008, 10:02 AM
Actually, in the mysql_connect request, it should be


mysql_connect($hostname,$username,$password)

$hostname should be "localhost"

Then, in the mysql_select_db request, it should be


mysql_select_db($bhuser_database)


i have the format you listed above in correctly and it's still spitting out error messages.

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'XYZ-REMOVED'@'localhost' (using password: YES) in /home/XYZ-REMOVED/database.inc.php on line 10

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'XYZ-REMOVED'@'localhost' (using password: NO) in /home/XYZ-REMOVED/database.inc.php on line 11

i typically put include "database.inc.php" so i can keep the files separate. not sure what the deal is here. i'm still a n00b. any help will be appreicated. (also new BH user...)

messels
05-08-2008, 10:03 AM
also, i've got this set up somewhere else so i'm just scratching my head why it's working on another server but not on bh...

messels
05-08-2008, 11:26 AM
nm.

guess the lesson is just to check and double check before opening my big fat mouth. hahaha.

database.inc.php:

$hostname = "nunya";
$database = "nunya";
$username = "nunya";
$password = "nunya";

$db_conn = mysql_connect ($hostname,$username, $password);

if (!$db_conn)
{echo mysql_error();}

$db_select = mysql_select_db ($database, $db_conn);

if (!$db_select)
{echo mysql_error();}