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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.