I need to store a snippet of HTML/PHP code in my table. I am using BLOB, but am not sure what is best to use, ASCII or UTF-8. What's the difference? Or shall I use TEXT altogether?
3 回答
You should use TEXT and set your whole set of tools to use UTF-8 only : your base, this column, but also HTML/PHP files (check your text editor and the headers), connections, and so on.
Today, except when you have to connect to specific (and old) databases, using UTF-8 everywhere is almost the sole sane choice.
Read this : http://www.utf8everywhere.org/
BLOB 是 varbinary,就像 TEXT 是 varchar。
本质上将二进制数据存储在 BLOB 中,并将文本存储在 TEXT 中。如果要存储实际的 html 代码,则使用 TEXT,如果要存储 html 文件,则使用 BLOB。
如果您需要能够执行 ORDER BY 或 LIKE 之类的操作,则不能使用 BLOB。
TEXT
当您要使用该字段的某种搜索功能(FULLTEXT)时,最好使用它。
BLOB
更适合存储 HTML 页面等数据和存储不会被搜索(FULLTEXT、LIKE)但只是加载的数据。