douchao1879 2014-03-30 18:54
浏览 281

'SQLSTATE [3D000]:无效的目录名称:1046从Laravel密码提醒返回后没有选择数据库

This is my home page route, where I get a random member:

Route::get('/', function()
{
    $member = User::orderBy(DB::raw('RAND()'))->first();
    return View::make('landing', compact('member'));
});

When the RemindersController's postRemind method sends the email, I'm doing this:

case Password::REMINDER_SENT:
    return Redirect::to('/')->with('flash_message', 'Whatever message...');

And the home page returns:

Illuminate \ Database \ QueryException
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: select * from `users` order by RAND() asc limit 1)

If I refresh the page right there, it fixes itself.. I'm using getenv() and .env.php files to fill the database connection values. If I switch from that to hard code them in, it fixes the problem. And if I go back to using getenv() it works too. However, as soon as I restart WAMP, I'm back to square 1.

What's going on?

  • 写回答

3条回答 默认 最新

  • duancenxiao0482 2014-04-03 08:47
    关注

    I had this problem when I replaced the hard coded values in database.php by using getenv().

    Are you sure that is loading the correct environment? you can check it in the terminal going to the route of your project and doing

    php artisan env

    If is not the correct one, you can fix it in the file start.php

    For example, if your local environment file (in the root of your project) is called ".env.local.php" in the file start.php you should have something like

    $env = 'yourHostName.local'

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊