XML或数据库表存储设置

编程入门 行业动态 更新时间:2024-10-26 22:18:12
本文介绍了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或数据库表存储设置

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

发布评论

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

>www.elefans.com

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