Storing website content: database or file?

I am creating a website and I plan to publish various kinds of posts, such as textbooks, articles, etc. I am going to manage it with php, but when it comes to storing the contents of each message, the very text that will be displayed, which option: use a separate text file or add it for each record in the database?

I see no reason why not use the database directly to store content, but this is the first time I use a database and I feel wrong.

What is your experience on this?

+4
source share
3 answers

Good friends. I will visit this question again for the benefit of those who read this answer. After a lot of trial and error, I came to the conclusion that saving text in a database is very convenient and easy to manipulate. Thus, all my data is now in the database. I used to have some details in the database and the text part in the file, but now I have moved everything to the database.

The only problem is that when editing messages, the field is in the form of a title or tags or topics, etc. changes in simple html form. but for the main content, I created a text area. however I just need to cut and copy it from the text area to my favorite text editor. and after editing the copy and paste it back.

some of the advantages that made me put everything in the database,

  • EASY SEARCH: you can run queries, such as mysql LIKE, in your text (especially the main content).

  • EASY ESCAPING: you can easily run commands on your data to reset special characters and make them suitable for display, etc.

  • GETTING USER LOGIN: if you want the user to give you input, it makes sense to save his entry into the database, avoid it and manipulate it as necessary.

  • Functions such as moving tables, backing up, combining two records, organizing records with similar content in sequential order ... etc. are all easier in the database than in the file system.

  • the file system always has a problem with missing files, different file names, the wrong file specified for a different name, etc. etc.

  • I do not avoid user input before adding it to the database immediately before displaying. thus, constant changes are not saved in the text (I don’t know if this is good or not)

+3
source

Infact I also do something like you. However, I came to the conclusion, as explained below (almost the same as mentioned in the answer above me). I hope you must have made a decision, but still I will explain it in such a way that it will be useful for the future.

My solution: I have a table called content_table that contains information about each article, post, or anything else that I write. The main (text part) of articles / messages is placed in a directory in a .php or .txt file. When a user clicks on an article to read, the article’s presentation is created dynamically using the information in the database and then pulling the text part (I call it main content) from the .txt file. The database contains information like _content_id_, date of creation, author, catagory (most of them become meta tags).

The two main advantages are:

  • lower datbase performance
  • Easy to edit text content.
+2
source

I give comments based on my experience,

In addition to attachments, you can store things in the database, why, because content management, backup, restore, query, search, especially full-text search will be easy.

Store the attached files in a folder and save the path in the DB tables.

Moreover, if you want to implement a search inside attachments, you can go to a search engine such as lucene, which is effective for finding static content.

saving attachments in the database or in the file system to the level important for files.

+1
source

Source: https://habr.com/ru/post/1402628/


All Articles