Tutorial :DB or flat file?


Just one little question. Shall i put the HTML textarea content into a DB or a flat file? The textarea content can be very long (like an article or a project).

Thanks for helping. Silvio.


Use text type instead of string, varchar type in db.

Note:-Text fields in mysql are limited to 65kb


OR You should look at using MySQL's LONGBLOB or LONGTEXT data type. They can store up to 4 gigabytes of binary or textual data, respectively.


Here are some pros and cons off the top of my head (I've done it both ways with varying levels of success):

Database Pros

  • Well known model for reading / writing data.
  • If the rest of your application is based on a database, this solution fits nicely.
  • The db has concurrency mechanisms already in place.
  • As long as you back up your database, your documents are backed up to (and in sync with the state of your database).

Database Cons

  • Theoretically, it is less efficient to pull a file from a database than directly from the file system. The db server has to read from disk, translate into its network protocol, etc.
  • The serving of these files from the db is a potential scalability bottleneck if only using one database server.

Flat File Pros

  • Dirt simple operations: Write, Delete, Read.
  • Presumably low overhead. If serving from web, the server can just be pointed to the files.

Flat File Cons

  • You have to deal with concurrency operations (what if one user wants to write to the file while another is reading, etc). This may or may not be an issue in your case.
  • It's one more type of information to back up / keep in sync / maintain.
  • You have to deal with security of the files as a separate issue from the rest of the data in the database.


Database without a doubt.

There's not much point in flat files because when you start expanding which you will do then you have to create more files and it's easier to lose track.

Start with a database and when you grow you can do things much faster and more complex selections by using structured query language the name says it all.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »