dongshuo5101 2016-01-29 02:13
浏览 143
已采纳

laravel使用.env但不在config \ database.php中使用config?

I'm learning laravel. I newly created a project and trying to create model, i set up the db config database.php and type php artisan migrate, but there is a error message

C:\xampp\htdocs\l1\blog>php artisan migrate


  [PDOException]
  SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin
  g password: YES)

I see it is using .env config but not using config in my config.php, why?

  • 写回答

1条回答 默认 最新

  • dongqiang2069 2016-01-29 09:43
    关注

    You can change the .env file to suit your database config settings as follows

    DB_HOST=localhost
    DB_MAIN=MYDB
    DB_USERNAME=root
    DB_PASSWORD=root
    

    Change the values of those keys according to your database connection. And place them in .env file.

    restart your server once and proceed.

    Other wise you can directly place those values in database.php file by replacing something like env('DB_USERNAME'),env('DB_PASSWORD') with direct values in either single or double quotes as follows

     'main' => [
            'driver'    => 'mysql',
            'host'      =>  '',
            'database'  =>  'mydb',
            'username'  => 'root',
            'password'  => 'root123',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],
    

    The code actually present in database.php file can be something as follows

          'main' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_MAIN', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],
    

    You can simply replace these values with above mentioned values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构