因为我也在笔记本和destkop上进行开发,所以我也想使用可以随时连接的sql服务器.
Becouse I developing on my notebook and on my destkop, too I want to use an sql server what I can connect anytime.
在开发环境中,我想与此连接,而在生产环境中,则要使用另一个.我该如何实现?
I want to connect to this when I'm on the development enviroment and use an other when I'm on production. How can I achieve this?
我在config/database中尝试过此操作:
if('env' == 'development'){ $host = 'mysqlserver.alias'; $database = 'mydb'; $username = 'myuname'; $password = 'mypwd'; } else { $host = whatsintheenv; $database = whatsintheenv; $username = whatsintheenv; $password = whatsintheenv; }推荐答案
这应该由您的环境配置通过.env文件处理.
This should be handled by your environment configuration via the .env file.
如果还没有.env文件,请复制.env.example.在其中,您将找到以下设置:
If you don't have a .env file yet, make a copy of .env.example. In there, you'll find these settings:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret只需修改这些值即可连接到正确的数据库服务器.
Simply modify these values to connect to the correct database server.
.env文件已从源代码管理中排除,因此您的笔记本和台式机在此文件中可以具有不同的内容.
The .env file is excluded from source control, so your notebook and your desktop can have different contents in this file.
更多推荐
如何在开发和生产上使用不同的数据库
发布评论