XML或数据库表存储设置 [英] XML or Database Table to store settings

查看:130
本文介绍了XML或数据库表存储设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将开始在PHP中使用MySQL作为后端编写一个网站。我必须做出的第一个决定之一是是否将数据库表或XML文件中存储站点设置。我想到将它们存储为键/值对,无论使用哪种存储。这可能是最灵活和最好的方式。

I am about to start writing a site in PHP using MySQL as back-end. One of the first decisions that I have to make is whether to store site settings in a database table or in a XML file. I thought about storing them as key/value pairs, no matter which storage I use. It's probably the most flexible and best way to do it.

由于这两种方法都比较容易实现和使用,我的担心是性能。哪一个更快?我应该使用哪一个?为什么?

Since both ways are relatively simple to implement and use, my worries are about performance. Which one is faster ? Which one should I use ? Why ?

PS:将设置存储在.ini文件中有多容易?它们可以通过PHP脚本轻松更改,而不是由用户/ sysadmin手动更改?

PS: How easy would it be to store the settings in an .ini file ? Can they be changed easily by a PHP script rather than manually by the user/sysadmin ?

此外,如果我将设置存储在mysql表中,sysadmin可以轻松缓存那个(非常小)表在RAM中。他可以用XML文件吗?

Also, if I would store the settings in a mysql table, the sysadmin can easily cache that (very small) table in RAM. Can he do that with an XML file ?

推荐答案

我假设配置是每个用户。
首先我建议你写一个包装类,它将访问配置。这样,你只能在一个类中而不是在所有代码中更改配置的核心。

I assume the configuration is per user. Firstly I would suggest you to write a wrapper class which will access the configuration. That way you could only change the core of configuration in one class not in all code.

class configuration {
  public function get_user_configuration() {
    // return users configuration
  }
}

我认为在数据库中存储配置会更容易。因为这样配置可能会每天备份,并且可以轻松导出。

I think it would be easier to store configuration in database. Because then the configuration probably will be backed up daily and can be easily exported.

缓存此配置是一个好主意。最简单的方法是将其缓存在会话中。您也可以尝试memcache或APC。

Caching this configuration is a good idea. The easiest way would be to cache it in session. You could also try memcache or APC.

这篇关于XML或数据库表存储设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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