如何在开发和生产上使用不同的数据库

编程入门 行业动态 更新时间:2024-10-28 20:18:01
本文介绍了如何在开发和生产上使用不同的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

如何在开发和生产上使用不同的数据库

本文发布于:2023-10-24 09:09:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523532.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生产上   数据库   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!