什么是最好的排序规则用于MySQL与PHP? [英] What is the best collation to use for MySQL with PHP?

查看:118
本文介绍了什么是最好的排序规则用于MySQL与PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果在一般的网站MySQL中有没有一个最好的排序选项,那么你不能100%确定输入的内容?我明白所有的编码应该是一样的,比如MySQL,Apache,HTML和PHP里面的任何东西。



过去我已经设置了PHP, UTF-8,但哪个排序规则与MySQL匹配?我认为这是UTF-8之一,但是我使用了 utf8_unicode_ci utf8_general_ci utf8_bin before。

解决方案

主要区别是排序精度(当比较字符语言)和表现。唯一特别的是utf8_bin,用于比较二进制格式的字符。



utf8_general_ci utf8_unicode_ci ,但不太准确(排序)。特定语言utf8编码(例如 utf8_swedish_ci )包含其他语言规则,使它们能够为这些语言排序最准确。大多数情况下,我使用 utf8_unicode_ci (我更喜欢精确到小的性能改进),除非我有一个很好的理由喜欢一种特定的语言。



您可以阅读更多关于MySQL手册上的特定unicode字符集 - http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html


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.

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.

解决方案

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 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.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆