开发者

PDO connect error on xampp for windows

开发者 https://www.devze.com 2023-04-07 10:19 出处:网络
I\'m new to PDO and am trying to use it on xampp for windows. I keep getting an error relating to the host and have tried changing \'localhost\' to everything possible such as ip address and sockets b

I'm new to PDO and am trying to use it on xampp for windows. I keep getting an error relating to the host and have tried changing 'localhost' to everything possible such as ip address and sockets but i believe i'm not doing it right. I've also tried changing the variable for pdo_mysql.default_socket but I don't believe that it's working/I'm doing that right either.This is 开发者_开发技巧the error I'm getting:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] [1044] Access denied for user 'admin'@'localhost' to database ''xxxxxx''' in C:\xampp\htdocs\faculty\classes\db.class.php

This is what i currently have in my php

self::$instance = new PDO("mysql:host=localhost;dbname='xxxxxx'", 'admin', 'xxxxxxx');


remove single quotes around dbname as in

self::$instance = new PDO("mysql:host=localhost;dbname=xxxxxx", 'admin', 'xxxxxxx');


Have you created an account for admin@localhost in mysql? PDO's connecting just fine, but you're using incorrect credentials to log into the database.

Specific docs on creating accounts: http://dev.mysql.com/doc/refman/5.5/en/adding-users.html


I had the same problem today and turns out my xampp mysql database had two "any" entries that were generating a warning in the users page of phpmyadmin that I was ignoring.

I managed to connect with PDO once I removed those two entries... go figure.

To sum up: remove the "any" users from your php users list, if they are there.

0

精彩评论

暂无评论...
验证码 换一张
取 消