A: 

'Access denied' means you are connecting to the DB server properly, but the user/host combination you're connecting as (and from) does not have permission to access the server and/or specified database. You can check the permissions from within the mysql monitor with show grants for user@hostname (e.g. whatever your DB_USER and DB_PASS defines are).

Remember that MySQL's user system is completely seperate from the operating system's user system, so having a login account on the server does not automatically grant you an account in MySQL.

Full docs on the permissions granting system are here on dev.mysql.com.

edit:

You should NEVER connect to the server as root. Create a new database user with just enough privileges you need on whatever database(s) are required. Connecting as root is just asking for trouble, including possibly opening your server up to remote compromises.

Unless your web app requires modifying tables on-the-fly, something like this should be enough permissions for most everything to work just fine:

GRANT insert,select,update,delete on somedatabase.* TO username@localhost IDENTIFIED BY 'somepassword';

And then use DB_USER = 'username' and DB_PASS = 'somepassword' in your connection

That all being said, have you verified that DB_USER, DB_PASS, and DB_SERVER are properly set inside your class? Also note that for MySQL's purposes, combinations of user@host are considered distinct accounts. 'root@localhost' and '[email protected]' may really be the same thing, but MySQL considers them utterly seperate and distinct.

Marc B
Don't forget that it could also mean that the selected user needs a password, and you're not passing one
Slokun
I check show grants root@localhost and it shows grant ALL root. what is need to be done
i set the password but still getting the same error.what should i do to solve the error because i tried so hard please help me out
mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\photo_gallery\includes\database.php on line 56Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\photo_gallery\includes\database.php on line 56The Query has problemAccess denied for user 'SYSTEM'@'localhost' (using password: NO)
Try skipping on your constant DB_USER/DB_PASS/DB_SERVER, and try hardcoding the relevant values in the connect() call. If that works, then you've got a scoping issue, or are not setting the constants properly.
Marc B
Oh, and of course, you're saying "Access denied for user 'SYSTEM'", but are checking permissions for user 'root'. Please make sure you're actually using the correct usernames before you start flooding this site with multiple copies of your question.
Marc B
A: 

Have you populated the DB_SERVER, _NAME, _USER, _PASS?

totallymike
thnx i figure out where the things went wrong
A: 

I had the same issue in different forms. But two things to make sure - make sure you didn't close the connection before the query and make sure the link didn't go away. With the original mysql extension this sometimes happens. Testing for this can be done by "get_resource_type" - if the connection isn't of type mysql link, you need to reconnect.

John Thomas
A: 

Try using 127.0.0.1 instead of localhost. On certain MySQL drivers(particularly on OS X, IIRC), localhost actually refers to a socket connection instead of the local system.

notJim