dqz30992 2017-02-18 15:05
浏览 345
已采纳

连接DB在laravel 5中[关闭]

I am trying to learn laravel.I got a problem with db connection.i did everything to connect set host name,user,db and password also but still got error and not able to connect with my DB

Error:

FatalErrorException in MainModel.php line 17: Class 'App\DB' not found

Db Configuration:

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

Thanks in advance

  • 写回答

2条回答 默认 最新

  • douxunnian0423 2017-02-18 15:41
    关注

    It seems that you put the DB connection values in the wrong place. This is how the env function works env($name, $defaultValue)

    Basically you're telling env to return 'root' as username, but only if DB_USERNAME doesn't exists. Looking at the error you posted in your comments, it seems that you're trying to connect as homestead, which is usually the default value in your .env file.

    If you have a .env file in your root folder, then that's where you should put your values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题