1

I'm uploading my website on HostGator, but I have a problem with MySql, i get this error :

Access denied for user 'hostgatoruser'@'localhost' (using password: NO)

And this is my php code :

try
{
    $DB = new PDO('mysql:host=localhost;dbname=hostgatoruser_database', 'hostgatoruser_abc', '********');
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}

Why the error tells me Access denied for user "hostgatoruser@localhost" instead of "hostgatoruser_abc" ? How to fix it ?

EDIT: OK, the problem was caused by the mysql_real_escape_string functions, so I removed them. I still dunno why I can't use mysql_real_escape_string...

user3620454
  • 11
  • 1
  • 4
  • It seems you don`t need a password to connect to the db (similar: http://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno) – ka_lin Sep 03 '14 at 15:31
  • but when I don't use the password, it says Access denied for user "hostgatoruser_abc@localhost" (using password: NO) – user3620454 Sep 03 '14 at 15:37
  • If it only gives you the first error when you use a password, check that your password doesn't have any characters that might cause problems. Single quotes, backslashes, etc. – Jeremiah Winsley Sep 03 '14 at 15:44
  • My password uses six numbers only – user3620454 Sep 03 '14 at 15:47
  • Have you contacted hostgator's support? – j08691 Sep 03 '14 at 15:57
  • @user3620454: Glad you resolved your issue. `mysql_real_escape` does not work with PDO because they do not know of each other and do not share credentials. If you want to know more, you should ask a specific question. – Yogu Sep 03 '14 at 17:46
  • So, I searched on the net, and with the PDO class I only need to use prepared statements to protect my database – user3620454 Sep 05 '14 at 17:01
  • As I can see on the net, I don't need to use – user3620454 Sep 05 '14 at 17:02

1 Answers1

0

As well as some of the comments here suggesting you check your username/password, it's also worth checking that the user has got permissions granted for that particular database.

You can find out what permissions you've been given by running:

SHOW GRANTS FOR 'hostgatoruser'@'localhost';
managedheap84
  • 841
  • 2
  • 10
  • 22