PDA

View Full Version : the classic MYSQL connect problem



castmitigation
05-20-2008, 03:56 PM
Hi guys, Im having a problem here so far I havent been able to solve at all.

- I created a user name "myuser" for "my_database"
- I gave this user all the permissions to this database so its administrator.
- Im trying to connect to the database and all I recieve is access denied

this is my code

$username = "user";
$password = "psw";
$database = "mysite_db";
$hostname = $_SERVER['HTTP_HOST'];

$dbh = mysqli_connect($hostname, $username, $password, $database);

can somebody tell me which might be the reason?

I noticed that everytime i create a user in cpanel it automaticly appends "mysite_" to every user i create so all the users look like "mysite_username". Ive tried both and nothing so this is not the problem either i guess.

thanks in advance.

RDM
05-20-2008, 04:03 PM
The first thing I see is hostname. The hostname is localhost not $_SERVER['HTTP_HOST'];

Second thing, and you may already be doing this, but the username and database name must include the first 8 letters of your domain name, which is also the same as your cpanel username.

So if my domain was mycooldomain.com, then this is how I'd connect to the MySQL

Username: mycooldo_user
Password: p@ssword
Database: mycooldo_database
Host: localhost