【问题标题】:CakePHP 4.0 database configurationCakePHP 4.0 数据库配置
【发布时间】:2020-04-28 18:24:29
【问题描述】:
    '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 数据库,我在哪里发现你问的错误:

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)

我想利用该错误找到解决错误的解决方案。 感谢所有帮助。烘烤!

【问题讨论】:

  • 好像用户 'my_app' 没有权限,在 phpmyadmin(或者你用什么)上为那个用户添加规则。
  • 用户名:root 我将用户名分配为 root,但仍然调用 my_app 加上已定义为 root 的用户,但调用到 my_app@localhost
  • 奇怪,你确定密码正确吗?用 root 很多时间是空的。
  • 你就是这么说的:$user = 'root'; $密码='root';仍在寻找答案。
  • 答案可能here

标签: php mysql cakephp configuration cakephp-4.x


【解决方案1】:

您需要检查您是否有config/app_local.php,它会覆盖config/app.php 中的设置。

【讨论】:

  • 我让 config/app_local.php 工作。效果很好,我对 config/app_local.php 没有任何问题。
【解决方案2】:

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

从 CakePHP 4 开始,默认的应用程序模板生成 loads an additional configuration file named app_local.php,它会覆盖一些设置,包括数据源配置。

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

另见

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 2013-12-23
    • 2011-01-18
    • 2014-05-23
    相关资源
    最近更新 更多