0

I'm building a social networking type site that will be storing large chunks of text that's entered by users, such as blog entries and private messages. As such, these will be entered once, with minimal revisions, but many reads by multiple users over time. I'm using MySQL, by the way.

My concerns are:

  1. Storing large blocks of text on the database will fill the database to capacity eventually.

  2. I read somewhere that storing user text in flat files is a security risk? (The filenames will be generated dynamically by the PHP, not by the user.)

  3. Storing them as text files may cause them to become out of sync if I ever have to reinitialize the database and restore it from backups.

What are all your thoughts and advice, pros and cons?

Fredashay
  • 1,013
  • 3
  • 10
  • 16
  • You would probably get more of a discussion on implementation on programmers.stackexchange.com, At stackoverflow, we focus more on answer specific technical problems. Such as how to store the file on DB. – Churk Mar 30 '12 at 22:38
  • In regards to 1. Storing them as files will eventually fill the disk to capacity. Six of one, half-dozen of the other, IMHO. – jpm Mar 30 '12 at 22:38
  • Don't store the file in the database... [only store a path to the file on the file system](http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay). – Michael Fredrickson Mar 30 '12 at 22:39

2 Answers2

2

Given these facts:

  1. Disk is cheap
  2. Databases are very fast, very good and very easy at managing this kind of data
  3. Blowing capacity is rarely a problem for things like blog entries (unless you are facebook)

You should store it in a DB.

Also, you're breaking one of the "golden rules" of software development: Don't optimize early. Your file-based idea is an optimization, so don't do it - just use the (easier) database. If it becomes a problem, worry about it then (it probably never will).

Bohemian
  • 412,405
  • 93
  • 575
  • 722
1

Store the file in a separate table with a reference to the record. So u r not taking xxx resource for a particular field in the DB when it is a nullable field. Also before storing the blog, compress the content. But this is just an opinion on implementation.

Churk
  • 4,556
  • 5
  • 22
  • 37