首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CakePHP 4.0数据库配置

CakePHP 4.0数据库配置
EN

Stack Overflow用户
提问于 2020-01-11 08:50:12
回答 2查看 3.1K关注 0票数 1
代码语言:javascript
运行
复制
    'default' => [
        'className' => Connection::class,
        'driver' => Mysql::class,
        'persistent' => false,

        'username' => 'root',
        'password' => 'root',
        'port' => '8889',

        'database' => 'rajasthan_skill_development',
        'timezone' => 'UTC',

        /**
         * For MariaDB/MySQL the internal default changed from utf8 to utf8mb4, aka full utf-8 support, in CakePHP 3.6
         */
        //'encoding' => 'utf8mb4',

        /**
         * If your MySQL server is configured with `skip-character-set-client-handshake`
         * then you MUST use the `flags` config to set your charset encoding.
         * For e.g. `'flags' => [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4']`
         */
        'flags' => [],
        'cacheMetadata' => true,
        'log' => false,

        /*
         * Set identifier quoting to true if you are using reserved words or
         * special characters in your table or column names. Enabling this
         * setting will result in queries built using the Query Builder having
         * identifiers quoted when creating SQL. It should be noted that this
         * decreases performance because each query needs to be traversed and
         * manipulated before being executed.
         */
        'quoteIdentifiers' => false,

        /*
         * During development, if using MySQL < 5.6, uncommenting the
         * following line could boost the speed at which schema metadata is
         * fetched from the database. It can also be set directly with the
         * mysql configuration directive 'innodb_stats_on_metadata = 0'
         * which is the recommended value in production environments
         */
        //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
    ],

上面的代码是config/app.php文件所在的,为了启用使用MySQL的数据库,我无法加载数据库并使用该配置与MySQL数据库连接,在哪里我会发现您问的错误:

代码语言:javascript
运行
复制
error file 
/Applications/MAMP/htdocs/sd/sd/vendor/cakephp/cakephp/src/Database/Driver.php

SQLSTATE[HY000] [1045] Access denied for user 'my_app'@'localhost' (using password: YES)

我想利用这个错误找到一个解决方案来解决错误。所有的帮助都是感激的。烤面包!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-11 12:42:05

可以说,app.php中的设置是默认/全局设置,可以通过加载其他配置文件来覆盖它们,这通常是为了为不同的环境、本地/开发、暂存、生产等提供更具体的配置。

从CakePHP 4开始,默认的应用程序模板生成和 ,这将覆盖一些设置,包括数据源配置。

长话短说,在而不是config/app.php中设置凭据。

另请参阅

票数 2
EN

Stack Overflow用户

发布于 2020-06-21 11:39:53

您需要检查是否有config/app_local.php,它重写了config/app.php中的设置。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59692914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档