PDO define()访问被拒绝

时间:2018-12-17 20:00:10

标签: php pdo

我正在尝试使用PDO进行连接,但收到以下错误

'Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)'

这是我的用户类别:

include "db_config.php";

class User
{

    //object variables
    public $pdo;
    public $user_data;

    public function __construct()
    {
        $this->pdo = new PDO(
            "mysql:host=" . DB_SERVER . ";dbname=" . DB_DATABASE, //DSN
            DB_USERNAME, //Username
            DB_PASSWORD //Password
    );

db_config.php:

//the address for the database server
define('DB_SERVER', 'localhost');

//the username for the database server
define('DB_USERNAME', 'root');

//the password for the database server
define('DB_PASSWORD', 'root');

//name of the databse
define('DB_DATABASE', 'cfs-ex');

不太确定如果我用'root'替换DB_PASSWORD会丢失什么,它可以正常工作,所以我认为数据库本身或密码没有什么问题

0 个答案:

没有答案