如何在数据库列中存储 HTML 的最佳实践

发布于 2024-09-05 09:15:33 字数 442 浏览 2 评论 0原文

我有一个动态修改表的应用程序,例如电子表格),然后在保存表单(表是其中的一部分)时,我将更改后的表(带有用户修改)与其余的一起存储在名为 html_Spreadhseet 的数据库列中表单数据。现在我只是以纯文本格式存储 html,并进行基本的字符转义...

我知道这可以存储为单独的文件,源表(html_workseeet)已经是。但从数据处理的角度来看,更容易将更改后的 html 表保存到列中或从列中保存,从而避免必须提出文件管理策略(该文件夹将位于哪个文件夹中,现在必须在备份中包含文件夹,现在存在安全问题)需要应用于文件,如何将数据库安全性与文件系统同步等),因此为了最大限度地减少这些问题,我只将 ... 部分存储在数据库列中。

我的问题是我应该 gzip HTML ,也许使用 JSON 或其他格式来轻松存储和检索数据库列中的 HTML,在数据库中存储 HTML 内容的最佳实践是什么?或者只是将其存储为我当前的转义文本列?

I have an application that modifies a table dynamically, think spreadsheet), then upon saving the form (which the table is part of) ,I store that changed table (with user modifications) in a database column named html_Spreadhseet,along with the rest of the form data. right now I'm just storing the html in a plain text format with basic escaping of characters...

I'm aware that this could be stored as a separate file, the source table (html_workseeet) already is. But from a data handling perspective its easier to save the changed html table to and from a column so as to avoid having to come up with a file management strategy (which folder will this live in, now must include folder in backups, security issues now need to apply to files, how to sync db security with file system etc.), so to minimize these issues I'm only storing the ... part in the database column.

My question is should I gzip the HTML , maybe use JSON, or some other format to easily store and retrieve the HTML from the database column, what is the best practice to store HTML content in a datbase? Or just store it as I currently am as an escaped text column?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我一直都在从未离去 2024-09-12 09:15:33

如果您想要做的是保存 HTML 以供重新显示,那么按原样保存它,然后通过存储过程检索它,并在需要时为他们重新显示它有什么问题吗?

假设您有一个 HTML 页面,它可以从 ThickBox 页面上的列表或选择选项中选择某种 ID。

通常对于这种情况,您可能会通过 $Ajax 可能是 JSon 查询数据库,也可能不会。

然后发送回 $Ajax 调用的结果将是您的结果数据。

然后用 DB SpreadSheet 替换保存 SpreadSheet 的 Div。

因此,为了回答您原来的问题,您可以使用某种 ID 来存储 SpreadSheet,将其存储为 Div 的 HTML。

检索时,您只需将 Div HTML 替换为您存储的内容即可。

If what you are trying to do is save the HTML for redisplay, what's wrong with saving it as is, then just retrieving it via a stored proc, and re-displaying it for them when needed?

Say you have an HTML page, which can select some kind of ID from a list, either on a ThickBox page, or from a select option.

Normally for this kind of situation, you would probably query the DB via $Ajax possibly JSon, or not.

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

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

So, in answer to your original question, you could store the SpreadSheet with some sort of ID, storing it as the HTML of the Div.

When retrieved, you merely replace the Div HTML, with what you have stored.

晨光如昨 2024-09-12 09:15:33

这取决于 HTML 的大小。压缩后,您可以将其存储为二进制 BLOB。大多数时候,最好在转义可能导致问题的 SQL 字符后直接存储数据。
正如多次被问到为什么要存储视图而不是模型?

It depends on the size of the HTML. You could store it as a binary BLOB after zipping it. Most of the time it is just best to store the data directly after escaping the SQL characters that may cause problems.
As asked many times why are you storing the view instead of the model ?

一直在等你来 2024-09-12 09:15:33

您可能应该硬着头皮解析表(也许使用 HTML 解析器),否则您将面临用户在表数据中存储破坏性 JavaScript 的风险。 (这意味着单元格内容也应该被解析)。数据仍然可以存储为 blob(可能是压缩的 CSV 或 JSON),但您需要确保它不会造成损坏。

You probably should bit the bullet and parse the table (using an HTML parser perhaps), as otherwise you risk the user storing damaging JavaScript in the table data. (This means the cell contents should be parsed as well). The data can still be stored as a blob (maybe compressed CSV or JSON), but you need to make certain it is not damaging.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文