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条)

报告相同问题?