CakePHP 4.0 database configuration

我们两清 提交于 2020-06-28 05:48:58

问题


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

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 want to resort that error find a solution figure out to resolve error. All help is appreciated. BAKE!


回答1:


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.

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.

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

See also

  • Cookbook > Configuration > Configuring your Application



回答2:


You need to check if you have config/app_local.php it overrides the setting in config/app.php.



来源:https://stackoverflow.com/questions/59692914/cakephp-4-0-database-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!