Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing website content: database or file?

I'm building a website, and I'm planning to publish various kinds of posts, like tutorials, articles, etc. I'm going to manage it with php, but when it comes to storing the content of each post, the very text that will be displayed, what's a better option: using a separate text file or adding it as an for each entry in the database?

I don't see a reason why not to use the database directly to store the content, but it's the first time I use a DB and that feels kind of wrong.

What's your experience in this matter?

like image 879
cangrejo Avatar asked Mar 21 '12 10:03

cangrejo


People also ask

Are websites stored in databases?

Most websites today are database driven. This means the content, code and other components are stored in a database. The pages on the site don't actually exist permanently.

Should I store files in the database or file system?

Database provides a proper data recovery process while file system did not. In terms of security the database is more secure then the file system (usually). The migration process is very easy in File system just copy and paste into the target while for database this task is not as simple.

Do I need a database for my website?

Do I always need to use a database for a web project? No, not at all. Static websites with no dynamic data will not require any data connection. Or, for some web applications data can be stored directly as a static file in a folder system (such as XML or even directly as HTML).

Where are content stored for website?

The internet is a collection of a large number of client-server based systems. So all files and other resources on it are stored on secondary storage devices of the respective servers. Servers of websites are termed as web servers.


1 Answers

Ok Friends I am visiting this question once again for the benefit of those who will read this answer. After a lot of trial and error I have reached a conclusion that keeping text in database is a lot convenient and easy to manipulate. Thus all my data is now with in database. Previously I had some details in database and the text part in file but now i have moved all to database.

The only problem is that when editing your posts the field like title or tags or subject etc are changed on a simple html form. but for the main content I have created a text area. however i just have to cut and copy it from the text area to my favorite text editor. and after the editing copy and paste it back.

some benefits that forced me to put every thing in database are

  1. EASY SEARCH: you can run quires like mysql LIKE on your text (specially main content).

  2. EASY ESCAPING: you can run commands easily on your data to escape special characters and make it suitable for display etc.

  3. GETTING INPUT FROM USER: if you want the user to give you input it makes sense to save his input in database , escape it and manipulate it as and when required.

  4. Functions like moving tables , back up, merging two records, arranging posts with similar content in sequential order... etc etc all is more easy in database than the file system.

  5. in file system there is always the problem of missing files, different file names, wrong file shown for different title etc etc

  6. I do not escape user input before adding it to database just before display. this way no permanent changes are stored to the text.(i don't know if that's ok or not)

like image 196
Bilal Tariq Avatar answered Oct 23 '22 17:10

Bilal Tariq