3

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?

CaffeinatedCM
  • 754
  • 1
  • 11
  • 24

4 Answers4

8

There are loads of reasons why they use databases and not flat files. Here are a few off the top of my head.

Referential integrity

Indexes and efficient searching

SQL Joins

Here are a couple more posts you can look at for more information :

If i can store my data in text files and easily can deal with these files, why should i use database like Mysql, oracle etc

Why use MySQL over flatfiles?

Why use SQL database?

Community
  • 1
  • 1
JohnP
  • 49,507
  • 13
  • 108
  • 140
4

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.

Joel Burget
  • 1,328
  • 8
  • 17
3

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.

Damien
  • 674
  • 5
  • 12
1

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.

Matty
  • 33,203
  • 13
  • 65
  • 93