且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP脚本不能连接到数据库?

更新时间:2021-10-24 22:46:43

很好,错误消息清楚地说,访问被拒绝,所以hostname / username / password /

Well, the error message clearly says that access is denied, so either hostname/username/password/database is wrong or the user doesn't have the required permissions.

如何设置权限,在本例中为all:

How to set up permissions, in this example all:

GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

Host是您要连接的地方。 可以用作wildchar。请参阅文档中的更多详细示例。 (您可以在错误消息btw中看到您的用户+主机)

Host is where you'd be connecting from. % can be used as a wildchar. See more detailed examples at the documentation. (you can see your user + host in the error message, btw)

另外,您应该在尝试使用数据库链接之前检查连接是否成功一个查询。

As a side note, you should check that connection was successful before trying to use the database link in a query.