-2

I try my very best to never use php and as thus i am not well versed in it I am having a issue that I don't understand at all here I have tried a number of things including not including the table reference in /config changing to from localhost as mysql host ect.

It will probably be something exceedingly obvious but im just not spotting it! I goes with out saying all the DB credentials are completely correct (And i can connect with it fine from scala and python) anway here's the error (the real username/password not there OFC)

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] [1044] Access denied for user 'username'@'10.1.1.43' to database 'a5555413_AudioPl.users'' in /home/a5555413/public_html/drive/auth_handler.php:153 Stack trace: #0 /home/a5555413/public_html/drive/auth_handler.php(153): PDO->__construct('mysql:host=mysq...', 'username...', 'passwd') #1 /home/a5555413/public_html/drive/auth_handler.php(74): AuthHandler->GetDbConnection() #2 /home/a5555413/public_html/drive/index.php(47): AuthHandler->AuthHandler('webui') #3 {main} thrown in /home/a5555413/public_html/drive/auth_handler.php on line 153

Connect code the const's are defined in a separate config file

function GetDbConnection() {
    $dbh = new PDO(Config::DB_PDO_CONNECT,
        Config::DB_PDO_USER,
        Config::DB_PDO_PASSWORD);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbConnection = $dbh;
    return $dbConnection;
  }
ccKep
  • 5,786
  • 19
  • 31
user1231175
  • 137
  • 1
  • 2
  • 6
  • 3
    You might want to link the code you're using to connect (without user/password, ofcourse). – ccKep May 06 '12 at 22:53
  • Seems to me that the user you're using for this action doesn't have the required privileges? – Sander May 06 '12 at 22:54
  • possible duplicate of [access denied for user @ 'localhost' to database ''](http://stackoverflow.com/questions/8621649/access-denied-for-user-localhost-to-database) – hakre May 06 '12 at 22:57
  • @hakre The database isn't localhost it's external but have tried with a local host version too I did do a proper search before asking couldn't find anything relevent. – user1231175 May 06 '12 at 22:58
  • @user1231175: How does that make a difference? – hakre May 06 '12 at 22:59
  • @sander thanks but the user definitely has the right privileges – user1231175 May 06 '12 at 23:00
  • @hakre that Question seems to just indicate lack of PWD/correct credentials but I definately have the correct credentials/privliges as can connect from same box using scala or python (as above) – user1231175 May 06 '12 at 23:04
  • There are three things: username (check:OK), password (check:OK), allowed host for the first two (check: FAIL). Just read the error message and double check you actually use the right username and password **from an allowed host**. Mysql differs here, and you are wrong thinking you use the right username and password. You don't. You do from localhost, but you don't do from that host. And btw. this has been asked about a 1000 thousand times, so search the site please, I was just hinting a possible duplicate. – hakre May 06 '12 at 23:06
  • Connecting to `"localhost"` and connecting to `"10.1.1.43"`, even if it's physically the same machine, are two different things. – ccKep May 06 '12 at 23:07
  • Sure but neither localhost or 10.1.1.43 appear in any of my code for the entire site (did c+F to check) the const DB_PDO_CONNECT is set correctly to the external DB and u@dblocation and p@dblocation are right too – user1231175 May 06 '12 at 23:13
  • As I said earlier, you might want to post some code (your PHP connect that doesn't work, maybe even your python connect that does work too). – ccKep May 06 '12 at 23:17
  • @ccKep thanks done will add config file code /python if needed – user1231175 May 06 '12 at 23:28
  • The config file values and the python code (that seems to work) are what's interesting here. Also, try using another mysql account to see if that makes a difference. This is with a 99 percent certainty a mysql user config error. – ccKep May 06 '12 at 23:29

2 Answers2

2

Access denied means you're using the wrong username/password, and/or the account you're accessing has not be properly created in MySQL.

What does a show grants for username@10.1.1.43 show?

if you created the account as username@machinename and MySQL is unable to do a reverse DNS lookup to change your IP back to machinename, you'll also get this error.

Marc B
  • 356,200
  • 43
  • 426
  • 500
0

Check the following:

1) You entered the right database hostname (this is not always localhost), username and password? 2) The user has permissions on database.

Let me know if you don't know how to check.

Pruthvi Raj Nadimpalli
  • 1,335
  • 1
  • 15
  • 30