cakephp 版本 4 全新安装数据库未连接

cakephp version 4 fresh install database not connecting

'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'username' => 'root',
            'password' => '000000',
            'database' => 'cakephp',
            'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'cacheMetadata' => true,

我在 xampp 中的 phpmyadmin 数据库没问题。

但是 cakephp 主页仍然显示

CakePHP is NOT able to connect to the database.
Connection to database could not be established: SQLSTATE[HY000] [1045] Access denied for user 'my_app'@'localhost' (using password: YES)

我最近遇到了这个问题,通过在config/app_local.php

中添加数据库配置解决了这个问题

根据 Cakephp 文档:

The application skeleton features a config/app.php file which should contain configuration that doesn’t vary across the various environments your application is deployed in.

The config/app_local.php file should contain the configuration data that varies between environments and should be managed by configuration management, or your deployment tooling

参考: CAKEPHP -> Configuration -> Configuring your Application