954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Database Connection Error

I can't figure out what is wrong since my codes are correct.

$host="localhost";
$username="";
$password="";
$db_name="database";
$tbl_name="members";


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("Cannot Find Database");


Keeps on saying the die statement.

I'm using WAMP, and yes. my database name is "database" and table is name is "member".
Or is my db name is a reserve word.

abelingaw
Posting Whiz in Training
205 posts since Jun 2008
Reputation Points: 66
Solved Threads: 26
 

"database" is a reserved word in mysql. Which die statement is it printing? Cannot connect or the Cannot Find Database?

kekkaishi
Junior Poster
164 posts since Oct 2009
Reputation Points: 28
Solved Threads: 37
 

Cannot Find Database

So i should change my db name then? or something else is wrong.

abelingaw
Posting Whiz in Training
205 posts since Jun 2008
Reputation Points: 66
Solved Threads: 26
 

Try not to use the reserved keywords. So try changing the name. It just might be it.

kekkaishi
Junior Poster
164 posts since Oct 2009
Reputation Points: 28
Solved Threads: 37
 

Change DB name but still get the same output..

Even checked privileges and their all fine. But still.

abelingaw
Posting Whiz in Training
205 posts since Jun 2008
Reputation Points: 66
Solved Threads: 26
 

you could try putting mysql_error() in you die() area, see what that gives back

phoenix_2000
Junior Poster
107 posts since Sep 2011
Reputation Points: 40
Solved Threads: 12
 

It returns this error:

Access denied for user ''@'localhost' to database 'students'
abelingaw
Posting Whiz in Training
205 posts since Jun 2008
Reputation Points: 66
Solved Threads: 26
 

Your database seems to be password protected.

Management software like phpmyadmin usually have default usernames/password, try something like root or administrator etc.
I'm sure you can find it on the internet: i don't know those defaults out of my head

phoenix_2000
Junior Poster
107 posts since Sep 2011
Reputation Points: 40
Solved Threads: 12
 

Try to use the default username = root and default password if you havent changed it.

rotten69
Posting Whiz
346 posts since May 2011
Reputation Points: 3
Solved Threads: 16
 

Solved, thanks rotten and all who replied..

abelingaw
Posting Whiz in Training
205 posts since Jun 2008
Reputation Points: 66
Solved Threads: 26
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You