CakePHP 4.0数据库配置 [英] CakePHP 4.0 database configuration

查看:202
本文介绍了CakePHP 4.0数据库配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    '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'],
    ],

上面的代码在哪里配置/app.php文件位于允许使用MySQL启用数据库的过程中,我无法加载数据库并使用该配置与MySQL数据库连接,在哪里可以找到您问的错误:

That above code where config/app.php file located so to enable database using MySQL i am unable to load database and connect with MySQL Database with that configuration where do i find error you ask :

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)

I想要利用该错误找到解决方案以解决错误。
感谢您的帮助。

I want to resort that error find a solution figure out to resolve error. All help is appreciated. BAKE!

推荐答案

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

The settings in app.php are the default/global settings so to speak, and they can be overridden by loading additional configuration files, that's usually done in order to provide more specific configuration for different environments, local/development, staging, production etc.

从CakePHP 4开始,默认的应用程序模板生成并 加载一个名为 app_local.php 的附加配置文件,该文件将覆盖某些设置,包括数据源配置。

As of CakePHP 4, the default application template generates and loads an additional configuration file named app_local.php, which overrides some settings, including the datasource configuration.

长话短说,请将凭据设置为 config / app_local.php 而不是 config / app.php

Long story short, set the credentials in config/app_local.php instead of config/app.php.

另请参见

这篇关于CakePHP 4.0数据库配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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