From looking at the way some forum softwares are storing data in a database (eg. phpBB uses MySQL databases for storing just about everything) I started to wonder why they do it that way? Couldn't it be just as fast and efficient to use.. maybe xsl with xslt to store forum topics and posts? Or to at least store the posts in a topic?
-
The main reason is so that they can reap the benefits of a relational database, such as easily searching for posts based on a dynamic set of criteria. – Chris Kuehl May 29 '11 at 17:49
-
Just to be sure, you're proposing to store the content in .xls -files-? – Stef May 29 '11 at 17:50
-
@Stef, no, he's proposing xsl format (eXtensible Stylesheet Language) – heximal May 29 '11 at 17:54
-
2Why do people store food in fridges instead of in a moldy cardboard box? Appropriate tools for appropriate jobs. – Marc B May 29 '11 at 17:54
-
@Marc: Why is a database appropriate? `` – Robert Harvey May 30 '11 at 21:47
4 Answers
There are loads of reasons why they use databases and not flat files. Here are a few off the top of my head.
Indexes and efficient searching
Here are a couple more posts you can look at for more information :
But this is exactly what databases have been designed and optimized for, storage and retrieval of data. Using a database allows the forum designer to focus on their problem and not worry about implementing storage as well. It wouldn't make sense to ignore all the work that has been done in the database world and instead implement your own solution. It would take more time, be more buggy, and not run as quickly.

- 1,328
- 8
- 17
Database engines handle all the problems of concurrency. Imagine that, two users try to write in your forum at the same time. If you store the post in files, the first attempt will lock the file so the second has to wait for the first to finish.
Otherwise if you want to search, it's much faster to do it in database than scanning all the files.
So basically, it's not a good idea to store data wich can be modified by useres simultaneously, and searching is much more efficient in database.

- 674
- 5
- 12
-
thanks for explaining the files being locked, I didn't even think about that! – CaffeinatedCM May 29 '11 at 18:17
Simply, easy access to data. It's a lot easier to find posts between a date, created by a user, or with certain keywords. You could do all of the above with flat file storage, but this would be IO intensive and slow. If you had the idea of storing each post in its own file, you'd then have the problem of running out of disk space, not because of lack of capacity, but because you'd have consumed all the available inodes.
Software such as this usually has a static caching feature - pages that don't change are written out to static HTML files, and those are served instead of hitting the database.
Mixing static caching with relational DB storage provides the best of both worlds.

- 33,203
- 13
- 65
- 93
-
1This was very useful, thanks! I wish I could give more then one person a check mark :( – CaffeinatedCM May 29 '11 at 18:16
-
1