简体   繁体   English

PDO 连接拒绝访问

[英]PDO connection refuses access

I am trying to add some records to my database using PDO to make my code more secure.我正在尝试使用 PDO 将一些记录添加到我的数据库中,以使我的代码更安全。 But it gives me a connection error:但它给了我一个连接错误:

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

The connection file includes two scripts, one is regular mysql and second one is my new PDO.连接文件包括两个脚本,一个是普通的mysql,第二个是我的新PDO。 The first one is working well, but the PDO throws an error.第一个运行良好,但 PDO 引发错误。 Am I doing something wrong over here?我在这里做错了吗?

EDIT: CODE DELETED DUE TO SOME SHIEET编辑:由于某些 SHIEET 已删除代码

Your first connection is to 127.0.0.1 , while your second connections is to localhost .您的第一个连接是127.0.0.1 ,而您的第二个连接是localhost

They might be the same, but from the server (mysql) side they are not.它们可能是相同的,但从服务器 (mysql) 端来看它们不是。 Use 127.0.0.1 in your PDO line and it should work.在您的 PDO 行中使用 127.0.0.1,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM