Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large strings: Text files or SQL DB?

Tags:

sql

database

php

I am coding a forum system using PHP.

I am currently storing a threads ID, title, author, views and other attributes in an SQL database and then storing the thread body (the HTML and BBcode) in text files inside a folder named after the thread ID.

In practise it's really simple to grab the database values then just grab the thread body from the text file, but I was wondering if this is the 'proper way'? I have personally no problems doing this but if it turns out it is massively inefficient and I should instead store both the thread body HTML and BBcode in the database instead then I will change.

However, to me it seems wrong to store such a (very possibly) huge string of multi-line text along with lots of different characters in a database - I was taught that databases are more for short field 'values' rather than website content.

I would just like a definitive answer to this because it's been bugging me for ages as to wherever I’ve been doing it properly.

Does anyone know how popular forum systems store threads?

Added Thanks for the answers, so it's best to store thread content in the database, what field type should i use? Also what about replies? Another table which has the thread ID and comment ID then the comment body? I'm new to this database stuff so thanks for your help.

like image 263
Tommo Avatar asked Feb 27 '26 10:02

Tommo


1 Answers

Confluence (a commercial wiki) stores the entire page content within a single column.

The reason to store large text in the database is:

  1. There's (hopefully) no disconnect between the value and the record(s) the text is associated with
  2. There are technologies like Full Text Search (FTS) to make finding specific strings in large amounts of text
  3. Simplified backup & restore process
like image 77
OMG Ponies Avatar answered Mar 01 '26 23:03

OMG Ponies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!