English 中文(简体)
是否应当将价值储存在数据库或XML或文本档案中?
原标题:Should I store values in the database or in an XML or text file?

我在我正在开发的网站上就数据储存提出了几个简单的问题。 该网站将允许用户拥有一个个人形象的空间,他们能够根据文字、图像、BB代码以及两者加以规范。 这些简介的特性限制在5,000左右。 我很想知道储存这一数据的最佳方式,因为储存在数据库中的数量似乎很大。

我正在考虑使用简单的文本文档储存数据,并将数据与用户ID命名。 你认为,访问和书写速度最好,而且会减损数据库读/正文的业绩,因为浏览和更新概况将成为网站的一大部分。

Thanks。 我期待着听取你的意见。

最佳回答

我将着手将其储存在数据库中,因为:

  1. All data in the database can use transactions to keep stuff consistent;
  2. A single insert (transaction) will take care of all your storage needs;
  3. A single select will retrieve all data;
  4. Backup the database and you are done;
  5. If you run into slowness, setting up a master-slave scheme or partitioning is easy;
  6. You can use database tools to search in the data;

另一方面,如果你使用档案系统:

  1. filesystems do not have transactions, what happens if an insert fails, and you need to rollback, the file has already been saved;
  2. what happens if the filesystem gets out-of-sync with the database?
  3. It complicates your code, adding to the bugpressure;
  4. Writing to the filesystem adds an extra security hole, because your DB-app can now write and perhaps overwrite existing files on the filesystem.

More generally
Using the filesystem is used because storing large blobs in a db can be slow.
However you should not optimize until slowness sets in. Premature optimization is the root of all evil.
Slowness may never be a problem and besides you can do lots of optimization in the DB as well.

问题回答

如果你已经使用一个数据库,就会更容易储存该数据库。 5,000个特性是没有的。 这里的表现似乎不相干。

把类似的东西输入数据库可能是最佳选择。 在你拥有至少是微乎其微的档案之前,任何象样的数据库都应予以罚款。

概况信息是否与现有数据库信息有任何关系? 简介信息的结构是否完全固定,用户是否在一定程度上控制了自己的概况结构? 你们有多少用户?

如果简介信息与数据库功能完全分开,或者如果信息结构明确无误,如果你没有足够档案,以便不削弱档案系统,那么就应考虑将信息储存在单独的XML档案中。

如果有大量情况说明,而且信息可以用于链接储存,那么我很可能把它放在一个数据库中。 如果与你的主要数据库的功能挂钩,它可能属于该数据库。 否则,你就只能考虑建立一个单独的数据库。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签