Best practices for storing HTML in a database column

I have an application that dynamically modifies a table, parses a spreadsheet), and then, saving the form (which is part of the table), I save this modified table (with user changes) in a database column called html_Spreadhseet, as well as the rest of the form data . right now I'm just storing html in text format with basic character escaping ...

I know that this can be saved as a separate file, the source table (html_workseeet) is already there. But from the point of view of data processing, it is easier to save the modified html table to and from the column, in order to avoid the need to come up with a file management strategy (in which folder it will live, now you need to include the folder in backup copies, security problems now need to be applied to files, how to synchronize db protection with file system, etc.), therefore, to minimize these problems, I save only a part ... in the database column.

My question is: should I gzip HTML possibly use JSON or some other format to easily store and retrieve HTML from a database column? What is the best practice of storing HTML content in datbase? Or just save it as I am currently a column with escaped text?

+4
source share
3 answers

If what you are trying to do is save the HTML for re-rendering, what is wrong with saving it, then just get it through the saved process and re-display it for them when necessary?

Say that you have an HTML page that can select some identifier from the list, either on the ThickBox page or in the selection option.

Usually for this kind of situation you are likely to query DB via $ Ajax, possibly JSon, or not.

Then the result sent back to the $ Ajax call will be your resulting data.

Then you replace the Div that holds your SpreadSheet with DB SpreadSheet.

So, in response to your original question, you can save SpreadSheet with some sort of identifier, saving it as HTML Div.

When you extract, you simply replace the HTML HTML with what you saved.

+1
source

It depends on the size of the HTML. You can save it as a binary blob after it closes. In most cases, it is best to store data immediately after escaping SQL characters, which can cause problems.
How many times were asked why you keep the view instead of the model?

0
source

You should probably defuse the marker and parse the table (possibly using an HTML parser), as otherwise you risk the user storing corrupted JavaScript in the table data. (This means that the contents of the cell must also be analyzed). Data can still be stored as blob (possibly compressed CSV or JSON), but you need to make sure that it does not hurt.

0
source

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


All Articles