如何在开发和生产上使用不同的数据库 [英] How to use different database on development than production

查看:82
本文介绍了如何在开发和生产上使用不同的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我也在笔记本和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.com'; 
    $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.

这篇关于如何在开发和生产上使用不同的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆