patternsqlMinor
Storing html in mysql text fields, or include files? (html formatted articles)
Viewed 0 times
fieldstextincludeformattedmysqlfilesarticlesstoringhtml
Problem
I'm wondering if I should store long html formatted articles in my MySQL database, or if it would be better to store a reference to a file, and include that instead. It is not just paragraphs, but lists, tables, images (``'s), and other containers containing side notes and such.
The articles are usually somewhere between 150 000 and 250 000 characters (including spaces). But that is excluding html tags.
It works fine storing it in database. But was wondering if there was a better approach?
There is no search options on this site.
The articles are usually somewhere between 150 000 and 250 000 characters (including spaces). But that is excluding html tags.
It works fine storing it in database. But was wondering if there was a better approach?
There is no search options on this site.
Solution
I would recommend you put as little HTML in your database as possible. One very popular design pattern for websites is the Model-View-Controller pattern.
Using that pattern your data (author, title, categories, article content, etc.) would be stored in the database without HTML tags and be called the Model. Then the structure of the HTML page would be stored in a file called the View. The Controller would be in charge of accepting the HTTP requests, requesting the appropriate data from the database, and merging/sending that data with/to the view.
Any common web programming platform should be able to accommodate this pattern.
Using that pattern your data (author, title, categories, article content, etc.) would be stored in the database without HTML tags and be called the Model. Then the structure of the HTML page would be stored in a file called the View. The Controller would be in charge of accepting the HTTP requests, requesting the appropriate data from the database, and merging/sending that data with/to the view.
Any common web programming platform should be able to accommodate this pattern.
Context
StackExchange Database Administrators Q#113120, answer score: 2
Revisions (0)
No revisions yet.