unuffact的PDOException:sqlstate [hy000] [1045]访问用户的访问权限' root'@@@' localhost' (使用密码:否)
当我尝试在Localhost上运行PHP代码时,则出现以下给出的错误:
致命错误:未被发现的PdoException:SQLSTATE [HY000] [1045]访问 拒绝用户'root'@'localhost'(使用密码:否) C:\ XAMPP \ HTDOCS \最终项目CSE-391 \ Project \ config.php:2
堆栈跟踪:
#0 c:\ xampp \ htdocs \最终项目cse-391 \ project \ project \ config.php(2):pdo-> __ construct('mysql:host = loca = loca = loca ...','root'','')
#1 C:\ XAMPP \ HTDOCS \最终项目CSE-391 \ Project \ Index.php(2):inclage('c:\ xampp \ htdocs ...')
#2 {main}扔在c:\ xampp \ htdocs \最终项目cse-391 \ project \ project \ project \ project.php上,第2行2
我需要建议解决此问题。
When I try to run my PHP code on localhost, then error given given below appears:
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access
denied for user 'root'@'localhost' (using password: NO) in
C:\xampp\htdocs\Final Project CSE-391\project\config.php:2
Stack trace:
#0 C:\xampp\htdocs\Final Project CSE-391\project\config.php(2): PDO->__construct('mysql:host=loca...', 'root', '')
#1 C:\xampp\htdocs\Final Project CSE-391\project\index.php(2): include('C:\xampp\htdocs...')
#2 {main} thrown in C:\xampp\htdocs\Final Project CSE-391\project\config.php on line 2
I need suggestion to solve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个错误的凭证问题。检查您在浏览器上使用的值登录到
phpMyAdmin
以确保将其放入连接配置之前是正确的。设置密码后,您可以输入错误的密码或将密码留给空白。
This is a wrong credential issue. Check the values you used on the browser to log into
PHPMyAdmin
to ensure it is correct before putting it in the connection config.You could have entered the wrong password or leaving password to blank after having set a password.
解决方案
我通过指向SQL端口来解决此问题:
$ host ='localhost:3307'
而不是$ host ='local -Host'
。例子
Solution
I fixed this by pointing to the SQL port:
$host = 'localhost:3307'
instead of$host='localhost'
.Example
如果phpmyadmin端口不是默认端口,则在主机上,它不仅应包括Localhost,还应指定端口,例如Localhost:3311。
示例
If the phpMyAdmin port is not the default port, then on the host, it should not only include localhost but also specify the port, for example, localhost:3311.
example
如果您像我有时使用密码生成器来创建密码。
您可能会收到这样的密码:
ljdke $ 7SWNZ00EN2ILWFS3NSVQ#
当您使用phpmyadmin时,它会正常工作。
如果您获得
sqlstate [hy000] [1045]访问用户
...错误。然后,您的密码中有一个字符,PHP不喜欢。
就我而言,这是密码末尾的“#”。
解决方案,更改密码。
If you used a password generator to create your password as I sometimes do.
You may get a password like this:
LJdKE$7swNZ00En2iLwFS3NSvq#
It will work fine when you use PhpMyAdmin.
If you get an
SQLSTATE[HY000] [1045] Access denied for user
... error.Then there is a character in your password that PHP does not like.
In my case, it was the '#' at the end of the password.
The solution, change the password.