用于 MySQL 和 PHP 的最佳排序规则是什么? [英] What is the best collation to use for MySQL with PHP?
问题描述
我想知道在 MySQL 中是否有一个最佳"选择,用于您不能 100% 确定将输入的内容的一般网站?我知道所有的编码都应该是相同的,例如 MySQL、Apache、HTML 和 PHP 中的任何内容.
I'm wondering if there is a "best" choice for collation in MySQL for a general website where you aren't 100% sure of what will be entered? I understand that all the encodings should be the same, such as MySQL, Apache, the HTML and anything inside PHP.
过去我已经将 PHP 设置为以UTF-8"输出,但是在 MySQL 中这与哪种排序规则匹配?我认为它是 UTF-8 之一,但我之前使用过 utf8_unicode_ci
、utf8_general_ci
和 utf8_bin
.
In the past I have set PHP to output in "UTF-8", but which collation does this match in MySQL? I'm thinking it's one of the UTF-8 ones, but I have used utf8_unicode_ci
, utf8_general_ci
, and utf8_bin
before.
推荐答案
主要区别在于排序准确性(比较语言中的字符时)和性能.唯一特殊的是utf8_bin,用于比较二进制格式的字符.
The main difference is sorting accuracy (when comparing characters in the language) and performance. The only special one is utf8_bin which is for comparing characters in binary format.
utf8_general_ci
比 utf8_unicode_ci
快一些,但不太准确(用于排序).特定语言 utf8 编码(例如 utf8_swedish_ci
)包含额外的语言规则,使它们能够最准确地对这些语言进行排序.大多数时候我使用 utf8_unicode_ci
(我更喜欢准确性而不是小的性能改进),除非我有充分的理由更喜欢特定语言.
utf8_general_ci
is somewhat faster than utf8_unicode_ci
, but less accurate (for sorting). The specific language utf8 encoding (such as utf8_swedish_ci
) contain additional language rules that make them the most accurate to sort for those languages. Most of the time I use utf8_unicode_ci
(I prefer accuracy to small performance improvements), unless I have a good reason to prefer a specific language.
您可以在 MySQL 手册上阅读有关特定 unicode 字符集的更多信息 - http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html
You can read more on specific unicode character sets on the MySQL manual - http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html
这篇关于用于 MySQL 和 PHP 的最佳排序规则是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!