在 mysql 中存储 html 代码的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9322569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:10:32  来源:igfitidea点击:

What's the best way to store html code in mysql?

mysql

提问by Francesco

Possible Duplicate:
What structure type do I use for HTML content (MySQL)

可能的重复:
我对 HTML 内容使用什么结构类型 (MySQL)

What's the best way to store html code in mysql?

在 mysql 中存储 html 代码的最佳方式是什么?

if i have et's say an entire page source code and I want to save it, what kind of data shoudl i use in mysql?

如果我有一个完整的页面源代码并且我想保存它,我应该在 mysql 中使用什么样的数据?

also, it it better to just save the code as a file, with a filename equal to an unique id created in mysql (maybe to save space in mysql?)

此外,最好将代码保存为文件,文件名等于在 mysql 中创建的唯一 ID(也许是为了节省 mysql 中的空间?)

采纳答案by Jeff

I would recommend TEXT. I think blobs are more for multimedia etc. than text.

我会推荐文本。我认为 blob 更适合多媒体等,而不是文本。

wikipedia blob

维基百科

回答by Naveen Kumar

Data type to store HTML in Database would be TEXT

在数据库中存储 HTML 的数据类型将是 TEXT

but you have to encode it using mysql_real_escape_string

但您必须使用 mysql_real_escape_string 对其进行编码

$html="Yor HTML";
$sql = "INSERT INTO tbl (html) 
VALUES ('" . mysql_real_escape_string($html) . "')"

or use Prepared Statements

或使用准备好的语句

回答by Sudhir Bastakoti

You can use BLOBor TEXT

您可以使用BLOBTEXT