4

I'm really having a strange Issue here, and it's really starting to annoy me. It's about the different behaviour of connections. I'm just trying to set up CakePHP, but the PDO cant conenct to the mysql Server.

Okey, step by step: It's a fresh computer, I just installed XAMPP (on Win7) and downloaded CakePHP. Nothing else was done. On phpMyAdmin, I created a user 'test' with PW 'test' and he owns the Database 'test'. Simple, right?

Here, the row of the User / Rights table in phpMysqlAdmin:

User Host Password Global Rights GRANT
test %    Yes      USAGE         No

Now, to the real Issue:

This works:

$link = mysql_connect('localhost', 'test'); //<- not using the 3. parameter, 'password'

But, what should work, doesnt:

$link = mysql_connect('localhost', 'test', 'test'); //<- using the 3. parameter, 'password'

And since I cant seem to 'remove' the 'using Password: YES' for PDO's, I cant connect with PDO's either (and cake Uses PDO's):

$dbh = new PDO('mysql:host=localhost;dbname=test', 'test', 'test');

Error Messages:

Error!: SQLSTATE[28000] [1045] Access denied for user 'test'@'localhost' (using password: YES)

It cant be so complicated, I just want to connect to a freshly installed DB, with the correct credentials. What am I doing wrong? I read trough many similar Questions, but didnt find a solution for my own Problem.

And yes, the password really is 'test' - I have no idea why the mysql_connect() whitout PW, can connect - is it using the username as PW by default?

This really cant be that hard

Thanks for the help, Wish you a nice day.

EDIT (answer to question)

Here the entry for the DB rights (in user: test): - the user really seems to have all rights for DB 'test'

Database Rights         GRANT 
test     ALL PRIVILEGES Nein
Katai
  • 2,773
  • 3
  • 31
  • 45
  • Have you grant permission for user test in datebase test,it seems that you have not given any permission to test user.Please set permission first for user test. – Rohit Choudhary May 03 '12 at 07:30
  • What about just passing an empty string as a password? – kuba May 03 '12 at 07:31
  • I created the DB 'test' automatically, over phpMyAdmin: there is a selection, that says something like 'creating DB with same name, and granting rights for it' (I edited my Post, you can see the rights at the bottom). - And yes, tried empty String. The problem really seems to be 'use password: YES' - as soon as that is 'No' it works. But PDO always seems to have that setting active – Katai May 03 '12 at 07:32
  • you should create a user with different username for database test and grant right, or you can modify this $link = mysql_connect('localhost', 'test', 'test'); to $link = mysql_connect('localhost', 'root', ''); if you have not given any password for root user. – Rohit Choudhary May 03 '12 at 07:35
  • mysql_connect('localhost', 'root', ''); works. Why does my own user not work then? Can it be, that phpMyAdmin does something wrong while creating user/DB togheter? Since (I edited the Post, see bottom) the user, seems to have all rights needed? (Rights: ALL PRIVILEGES) – Katai May 03 '12 at 07:38
  • change the user name in pdo $dbh = new PDO('mysql:host=localhost;dbname=test', 'Nein', 'yourpassword'); – Rohit Choudhary May 03 '12 at 07:38

1 Answers1

3

GRANT ALL ON test.* TO test@localhost IDENTIFIED BY "test";

Run the above query at the mysql shell and everything should work.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284