PDA

View Full Version : MySQL connection problems



BobbX
07-26-2006, 03:42 PM
I had a hosting account with a different online company and it was so much easier to open up a page that had a connection with my database. I tried using the example, with a little modification based on my info, but I'm still having problems connecting with Bluehost, what gives?

areidmtm
07-26-2006, 04:03 PM
lets see some code

BobbX
07-28-2006, 05:15 PM
ok, here is the exact code I have on my website minus login info, I've modified it from the old info to the new connection info :

class MySQLDB
{
var $connection; //The MySQL database connection
var $num_active_users; //Number of active users viewing site
var $num_active_guests; //Number of active guests viewing site
var $num_members; //Number of signed-up users
/* Note: call getNumMembers() to access $num_members! */

/* Class constructor */
function MySQLDB(){
/* Make connection to database */
$this->connection = @mysql_connect(localhost, DB_NAME, DB_PASSWORD) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

/**
* Only query database to find out number of members
* when getNumMembers() is called for the first time,
* until then, default value set.
*/
$this->num_members = -1;

there's more to the code, but this is where I'm having the problem.

areidmtm
07-28-2006, 05:21 PM
make sure you have set up a user and pasword and databse in the cPanel. Once you have done that, your username and database will begin with the first 8 letters of your main domain name.

youdomain.com

youdomai_database
youdomai_username

BobbX
07-28-2006, 05:35 PM
well if you're saying to do that, it comes back with:

Access denied for user 'USER_NAME'@'localhost' (using password: YES)

so something is still not right

dvessel
07-28-2006, 06:23 PM
Might be obvious and easy to miss but did you assign the user to the database through cpanel? Once you create the two, you still have to give permission for the user to access the database.