UTF-8数据库问题 [英] UTF-8 Database Problem

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

问题描述

我有一个具有UTF-8字符集的MySQL表,并尝试通过PHP表单插入该表时,数据库显示以下错误:

I've a MySQL table that has a UTF-8 charset and upon attempting to insert to it via a PHP form, the database gives the following error:

PDOStatement :: execute(): SQLSTATE [HY000]:一般错误:1366 字符串值不正确:"\ xE8" 列...

PDOStatement::execute(): SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE8' for column ...

有问题的字符是è",但考虑到数据库和表设置为UTF-8,我不明白为什么这应该是一个问题.

The character in question is 'è', yet I don't see why this should be a problem considering the database and table are set to UTF-8.

修改

我已经直接从mysql终端尝试过,并且遇到了同样的问题.

I've tried directly from the mysql terminal and have the same problem.

推荐答案

E8大于一字节UTF8字符中的最大可用字符7F:

E8 is greater than the maximum usable character 7F in a one-byte UTF8 character: http://en.wikipedia.org/wiki/UTF-8

似乎您的连接未设置为UTF8,而是其他一些8位编码,例如ISO Latin.如果将数据库设置为UTF8,则仅更改数据库内部使用的字符集,连接可能使用不同的默认值(对于较早的MySQL版本,为latin1),因此您应尝试在连接到数据库后发送初始SET CHARACTER SET utf-8.如果您有权访问my.cnf,也可以在此处设置正确的默认值,但是请记住,更改默认值可能会破坏在同一主机上运行的所有其他网站/应用.

It seems your connection is not set to UTF8 but some other 8 bit encoding like ISO Latin. If you set the database to UTF8 you only change the character set the database uses internally, connections may be on a different default value (latin1 for older MySQL versions) so you should try to send an initial SET CHARACTER SET utf-8 after connecting to the database. If you have access to my.cnf you can also set the correct default value there, but keep in mind that changing the default may break any other sites/apps running on the same host.

这篇关于UTF-8数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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