首页 > 解决方案 > 无法连接到数据库。主连接 [MySQLi]:用户 @ 的访问被拒绝(使用密码:是)

问题描述

CodeIgniter\Database\Exceptions\DatabaseException #8 无法连接到数据库。主连接 [MySQLi]:用户 'xxxx'@'localhost' 的访问被拒绝(使用密码:YES)

我正在尝试访问我的程序,但我无法连接数据库。我怎么做?因为我还是初学者

public $default = [
    'DSN'      => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'starter',
    'DBDriver' => 'MySQLi',
    'DBPrefix' => '',
    'pConnect' => false,
    'DBDebug'  => (ENVIRONMENT !== 'production'),
    'cacheOn'  => false,
    'cacheDir' => '',
    'charset'  => 'utf8',
    'DBCollat' => 'utf8_general_ci',
    'swapPre'  => '',
    'encrypt'  => false,
    'compress' => false,
    'strictOn' => false,
    'failover' => [],
    // 'failover' => array(),
    // 'save_queries'=> TRUE,
    'port'     => 3306,
];

public $tests = [
    'DSN'      => '',
    'hostname' => '127.0.0.1',
    'username' => 'root',
    'password' => '',
    'database' => ':memory:',
    'DBDriver' => 'SQLite3',
    'DBPrefix' => 'db_',  // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
    'pConnect' => false,
    'DBDebug'  => (ENVIRONMENT !== 'production ),
    'cacheOn'  => false,
    'cacheDir' => '',
    'charset'  => 'utf8',
    'DBCollat' => 'utf8_general_ci',
    'swapPre'  => '',
    'encrypt'  => false,
    'compress' => false,
    'strictOn' => false,
    'failover' => [],
    'port'     => 3306,
];

标签: phpdatabasecodeigniter-4

解决方案


推荐阅读