简体   繁体   English

将网站参数存储在数据库或平面文件中

[英]Storing website parameters in a database or flat files

For the most part, the 3 sites for an organization I run have a single MySQL database that they share. 在大多数情况下,我运营的组织的3个站点都共享一个MySQL数据库。 This allows them to interact with each other nicely. 这使他们可以很好地相互交流。

I have a bunch of simple parameters that the sites need to know about, and I wasn't sure what the best route to take is: 我有一些站点需要了解的简单参数,我不确定最好的方法是:

  1. Make a table with 2 fields (key, value) where I store the params 制作一个包含2个字段(键,值)的表,我在其中存储参数
  2. Store the values in one or many flat files 将值存储在一个或多个平面文件中

They each have advantages and disadvantages. 它们各有优缺点。

The database allows a single entry to be used for all three sites (however, this doesn't occur often), all the information is centralized, and the interface is already well defined. 该数据库允许对所有三个站点使用单个条目(但是,这种情况并不经常发生),所有信息都被集中化,并且接口已经被很好地定义。

The flat files are easier to work with as FTP and a text editor can be used in addition to website administration, the flat files can be written as PHP meaning the site doesn't have to do any parsing (just need to include the file and use the variables), but they can't be shared between sites. 平面文件更易于使用,因为FTP可以使用FTP,并且除了可以进行网站管理外,还可以使用文本编辑器,平面文件可以编写为PHP,这意味着该站点无需进行任何解析(只需要包含文件和使用变量),但不能在站点之间共享它们。

I can go on and on. 我可以继续下去。 What do you think is the better route to take? 您认为更好的选择是什么?

My opinion is to use a database if you have the chance. 我的看法是,如果有机会,请使用数据库。 It's easier on the long run. 从长远来看,这更容易。 You have built the website, with the flat files, but now the customer wants an additional page with slightly other parameters, so you have to add a new file. 您已经使用平面文件构建了网站,但是现在客户想要一个带有稍微其他参数的附加页面,因此您必须添加一个新文件。 Now you are done with this and he ask you again.. well, you get the point. 现在您已经完成了,他再次询问您。.恩,您明白了。

It is not organised at all. 它根本没有组织。 So if you have the chance to use a database, use it. 因此,如果您有机会使用数据库,请使用它。 There is reason why it is invented. 有理由发明它。

But just to get my thoughts clear and firmly know what you are talking about, please tell me more about the settings you would like to store. 但是,为了使我的想法更清楚并完全了解您在说什么,请告诉我更多有关您要存储的设置的信息。 I can imagine that you are talking about some global variables, or maybe even going to use a define(), but it is also possible you want to store strings. 我可以想象您正在谈论某些全局变量,甚至可能要使用define(),但也可能要存储字符串。 So please define "bunch of simple parameters" for us. 因此,请为我们定义“简单参数组合”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM