使用数据库而不是配置文件来存储配置
不幸的是,搜索此类材料给我带来了很多噪音,所以我想知道这里是否有人知道对于希望学习如何使用数据库而不是文件来存储站点配置信息的人来说有一个很好的资源。
我想我感兴趣的一些点是: 1)如何存储数据。像 e107 这样的一个阵列?每个可配置的单独行? 2)如何获取配置数据。全局数组?
Unfortunately searching for this kind of material produces a lot of noise for me so I was wondering if anyone here knew of a good resource for anyone wishing to learn how to use a database to store site configuration info rather than a file.
I guess some points I'm interested in are:
1) How to store the data. One array like e107? Separate row for each configurable?
2) How to get the configuration data. Global array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
考虑以下事项:
对于小型 Web 应用程序,我通常会选择配置文件。
一旦您拥有涉及网络和应用程序的基础设施,对于非 Web 服务器,将配置放在可集中访问的位置成为一个优势。这不一定是 SQL 数据库,有些人使用 LDAP 甚至 DNS。
Consider the following:
I would generally go for a config file, for small web applications.
Once you get as far as having an infrastructure involving web & non-web servers, putting the config in a centrally-accessible place becomes an advantage though. This doesn't have to be a SQL database, some people use LDAP or even DNS.
我要在教堂里发誓,并谦虚地指出,两者都可以做到:)
您可以将配置参数存储在数据库中,然后在保存参数时生成您需要的任何配置文件。
这是一种冗余形式,但它还具有以下优点:
I'm gonna swear in church and humbly point out that one can do both :)
You can store the configuration parameters in a database and then produce whatever configuration file you need when the parameters are saved.
This is a form of redundancy, but it also gives the following advantages:
每行一行,类似于 EAV。
当然,全局数组或对象听起来不错。
One row per, similar to EAV.
Sure, global array or object sounds fine.
对于用户通过 Web 界面更改的设置,您的方法非常常见。
您可以查看 WordPress 在数据库中存储配置的方式。
Your approach is very common for settings that users change through a web interface.
You might look at the way WordPress stores configuration in the database.
像这样的东西应该对你有用:
将你的键放入 prop 中,并将配置值放入 value 中。
Something like this should work for you:
Put your keys into prop, and the config values into value.