尝试连接到数据库时出现异常错误

编程入门 行业动态 更新时间:2024-10-27 02:27:29
本文介绍了尝试连接到数据库时出现异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在最后一天左右,我无法通过PHP连接到数据库。这是我的代码连接到数据库看起来像

$ con = mysqli_connect(localhost,root,password ); 这里是奇怪的错误。

PHP警告:mysqli_connect HY000 / 1045):第2行的用户'user'@'localhost'拒绝访问(使用密码:YES)

我通常会得到这个错误,如果凭据不正确,但我使用GUI和测试与确切凭证的连接,因此意味着,这不是问题。我刚开始随机得到这个错误,并重新启动我的电脑,重新安装MySQL,重新配置服务器我也试过 127.0.0.1 ,而不是 localhost 我在 localhost 所以我几乎完全控制任何东西,我没有弄乱任何导致这个问题。有任何想法吗?

解决方案

由于某种原因,该函数尝试使用user用户而不是root

您可以通过添加错误链接进一步调试:

$ con = mysqli_connect(myhost ,myuser,mypassw,mybd)或die(Error。mysqli_error($ con));

Over the last day or so I'm not able to connect to a database through PHP. Here's what my code connecting to the database looks like

$con = mysqli_connect("localhost","root","password","database"); And here's the strange error.

PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES) in - on line 2

I'd usually get that error if the credentials are incorrect, but I used a GUI and tested the connection with the exact credentials, where therefore means that, that is not the issue. I just started randomly getting this error and have restarted my computer, reinstalled MySQL, and reconfigure the server I've also tried 127.0.0.1 instead of localhost I'm on localhost so I have full control on pretty much anything and I didn't mess with anything causing this issue. Any ideas?

解决方案

For some reason the function is trying to connect using the "user" user instead of "root".

You can debug further by adding the error link:

$con= mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($con));

更多推荐

尝试连接到数据库时出现异常错误

本文发布于:2023-10-28 00:41:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   异常   错误   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!