Jump to content

unable to connect to database (Access Denied)


BrentonHale

Recommended Posts

Hello, I'm using MySQL version 5.1.36, php version 5.3.0 and apache version 2.2.11.  I am not able to connect to the database.  I get the following error message.

 

 

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

 


 

[<?php # Script 7.2 - mysql_connect.php

// This file contains the database access information.
// This file also establishes a connection to MySQL and selects the database.

// Set the database access information as constants.
DEFINE ('DB_USER', 'username');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'sitename');

// Make the connection.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());

// Select the database.
$mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error());
?>/code]


I don't use a password when I sign into the MySQL console. Could someone please tell me how to resolve this issue and what code I need to use?

Thank you!

Replace bold with your credentials

 

DEFINE ('DB_USER', 'YOUR DATABASE USERNAME');

DEFINE ('DB_PASSWORD', 'YOUR PASSWORD');

DEFINE ('DB_HOST', 'YOUR MYSQL HOST');

DEFINE ('DB_NAME', 'YOUR DATABASE NAME');

 

You get these from your webhost

 

Okay, that's what they were using in this book.  Let me explain: 

 

the database username is:  brenton

the password is:                password

mysql host is:                    localhost  (i don't have web hosting yet)

database name is:              sitename 

 

Now, I'm getting this error message:

 

Notice:  Undefined variable: mysql_select_db in C:\wamp\www\mysql_connect.php on line 16Fatal error:  Function name must be a string in C:\wamp\www\mysql_connect.php on line 16

Now, I'm getting this error message:

 

Notice:  Undefined variable: mysql_select_db in C:\wamp\www\mysql_connect.php on line 16Fatal error:  Function name must be a string in C:\wamp\www\mysql_connect.php on line 16

 

That's because "mysql_select_db()" is a function.  Remove the dollar sign.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.