'SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected' 从 Laravel 密码提示返回后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22748331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected' after returning from Laravel password reminder
提问by johnRivs
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:
当RemindersController
'spostRemind
方法发送电子邮件时,我这样做:
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.
如果我在那里刷新页面,它会自行修复.. 我正在使用getenv()
和.env.php
文件来填充数据库连接值。如果我从那个切换到硬编码,它可以解决问题。如果我回去使用getenv()
它也有效。但是,一旦我重新启动 WAMP,我就会回到第 1 方格。
What's going on?
这是怎么回事?
回答by Txaku
I had this problem when I replaced the hard coded values in database.php by using getenv().
当我使用 getenv() 替换 database.php 中的硬编码值时遇到了这个问题。
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
php工匠环境
If is not the correct one, you can fix it in the file start.php
如果不正确,您可以在文件 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
例如,如果你的本地环境文件(在你的项目的根目录中)在文件 start.php 中被称为“.env.local.php”,你应该有类似的东西
$env = 'yourHostName.local'
$env = '你的主机名.local'
回答by Tijo John
You can temporarily solve this problem by adding the database nameand usernameand passwordin the root folder .envfile.
您可以通过在根文件夹.env文件中添加数据库名称和用户名和密码来临时解决此问题。
回答by Dipen
I faced same problem you only have to change APP_ENV in .env file
我遇到了同样的问题,你只需要在 .env 文件中更改 APP_ENV
APP_ENV=localhost.local