utf8和utf8_general_ci [英] utf8 and utf8_general_ci

查看:266
本文介绍了utf8和utf8_general_ci的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将资料列插入资料库时发生问题。
当一行包含以下字符:'è','ò','ò','€','²','³'.... etc ...它返回一个这样的错误设置为 utf8 ):

I have problem inserting rows to my DB. When a row contains characters like: 'è', 'ò', 'ò', '€', '²', '³' .... etc ... it returns an error like this (charset set to utf8):

Incorrect string value: '\xE8 pass...' for column 'descrizione' at row 1 - INSERT INTO materiali.listino (codice,costruttore,descrizione,famiglia) VALUES ('E 251-230','Abb','Relè passo passo','Relè');

但是,如果我将字符集设置为 latin1 或* utf8_general_ci *工作正常,没有发现错误。

But, if I set the charset to latin1 or *utf8_general_ci* it works fine, and no errors are found.

有人能解释我为什么会这样吗?我一直认为 utf8 latin1

Can somebody explain me why does this happens? I always thought that utf8 was "larger" than latin1

编辑更大:我也试图使用mysql_real_escape_string,错误总是一样的!

I also tried to use mysql_real_escape_string, but the error was always the same!!!!

推荐答案

根据 doc ,默认排序规则为 utf8_general_ci
如果你想在字母表中不是 general_ci 的特定订单,你应该选择 utf8 _ * utf8 字符集提供的c $ c>排序规则,无论哪个符合您的要求。

According to the doc for UTF-8, the default collation is utf8_general_ci. If you want a specific order in your alphabet that is not the general_ci one, you should pick one of the utf8_* collation that are provided for the utf8 charset, whichever match your requirements in term of ordering.

您的表和您与数据库的连接应该编码在 utf8 中,最好是同一个排序规则,详细了解如何设置连接排序规则

Both your table and your connection to the DB should be encoded in utf8, preferably the same collation, read more about setting connection collation.

请使用 SET NAMES 的完整语法检查您的表排序规则并确保它 utf8 _ * >

To be completely safe you should check your table collation and make sure it's utf8_* and that your connection is too, using the complete syntax of SET NAMES

SET NAMES 'utf8' COLLATE 'utf8_general_ci'

您可以在此处找到有关不同归类的信息

You can find information about the different collation here

这篇关于utf8和utf8_general_ci的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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