数据库的正确PHP凭据导致错误,表明错误的凭据 [英] Correct PHP credentials for database leads to error signifying wrong credentials

查看:138
本文介绍了数据库的正确PHP凭据导致错误,表明错误的凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为demo的数据库。
我设置了一个名为username的用户名。
我设置了一个名为password的密码。
我连接到数据库。
我运行以下命令:

I create a database called 'demo'. I set a username called 'username'. I set a password called 'password'. I connect to the database. I run the following:

<?php
    define ('DB_NAME', 'demo');
    define ('DB_USER', 'username');
    define ('DB_PASSWORD', 'password');
    define ('DB_HOST', 'localhost');

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link){
    die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db(DB_NAME, $link);
    if (!$db_selected){
        die('Can\'t use ' . DB_NAME . ':' . mysql_error());
    }
    echo 'Connected successfully';
    ?>

我收到以下错误。


警告:mysql_connect():在C:\ xampp\htdocs\PhpProject2\index.php中拒绝用户'username'@'localhost'(使用密码:YES) 101
无法连接:用户'@'localhost'拒绝访问(使用密码:是)

Warning: mysql_connect(): Access denied for user 'username'@'localhost' (using password: YES) in C:\xampp\htdocs\PhpProject2\index.php on line 101 Could not connect: Access denied for user 'username'@'localhost' (using password: YES)

超越困惑。我使用的是正确的用户名和密码,但仍然无法连接,问题可能出在哪里?

I am beyond confused. I'm using the correct username and password, but still it doesn't connect, any ideas where the problem might lie?

推荐答案

您确定此凭证正确吗?或者,有这个用户权限这样做吗?

Are you sure that this credentials are correct? Alternatively, have this user permissions to do this?

如果您的用户没有密码,请参阅 this

If your user hasn't a password see this

SET PASSWORD [FOR user] = password_option

password_option: {
    PASSWORD('auth_string')
  | OLD_PASSWORD('auth_string')
  | 'hash_string'
}

示例

SET PASSWORD FOR 'username'@'localhost' = PASSWORD('password');

权限可以使用拨款

GRANT ALL ON demo.* TO 'username'@'localhost';

这篇关于数据库的正确PHP凭据导致错误,表明错误的凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆