MySQL更新错误当使用特殊字符MySQL update error when special characters are used
I was wondering if anyone had come across this one before. I have a customer who uses special characters in their product description field. Updating to a MySQL database works fine if we use their HTML equivalents but it fails if the character itself is used (copied from either character map or Word I would assume).
Has anyone seen this behaviour before? The character in question in this case is ø - and we can't seem to do a replace on it (in ASP at least) as the character comes though to the SQL string as a "?".
Any suggestions much appreciated - thanks!
This suggests a mismatched character set between your database (connection) and actual data.
Most likely, you're using ISO-8859-1 on your site, but MySQL thinks it should be getting UTF-8.
http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html describes what to check and how to change it. The simplest way is probably to run the query "SET NAMES latin1" when connecting to the database (assuming that's the character set you need).
Being a fan of Unicode, I'd suggest switching over to UTF-8 entirely, but I realize that this is not always a feasible option.
Edit: @markokocic: Collation only dictates the sorting order. Although this should of course match your character set, it does not affect the range of characters that can be stored in a field.
(原文：Thanks for the pointers. Client, Connection and results are set as UTF-8, database and server are set as latin1. Am I correct in assuming database and server need to be UTF-8 too?)Michael Madsen的回复:如果你去Unicode,是的。该网站应该宣布自己是utf - 8,和任何静态文本需要匹配。如果你不要# 39;t,然后让他们改变连接。你可以通过发送一组名称查询,当你打开它,或者通过改变相应的配置文件。
(原文：If you go Unicode, then yes. The site should declare itself as UTF-8 as well, and any static text will need to match this. If you don't, then leave them and change the connection instead. You can do this by sending the SET NAMES query when you open it, or by changing your config files accordingly.)
你试图整理为表设置为utf - 8或其他非latin1 / ascii中的一个。
Have you tried to set collation for the table to utf-8 or something non latin1/ascii.
- 数据库都支持自动创建索引吗?Do any databases support automatic Index Creation?
- 如何加入另一个MySQL表在使用主/明细在Netbeans示例表单吗?How to join another MySQL table when using Master/Detail Sample Form in Netbeans?
- MySQL条件语句MySQL conditional statement
- 我怎么能有MySQL写输出文件作为不同的用户? - How can I have MySQL write outfiles as a different user?
- SQL查询字段不包含$ x的地方SQL Query Where Field DOES NOT Contain $x
- MySQL更新错误当使用特殊字符MySQL update error when special characters are used
- 的最佳实践是什么命名数据库表提供自然组织?What is the best practice for naming database tables to provide natural organization?
- 在相同的表一对多关系One-to-many relationship in the same table
- 在MySQL外键吗?Foreign keys in MySQL?
- 帮助编写一个查询:混乱的顺序操作的GROUP BY和秩序Help write a query: Confusion over order of operations of GROUP BY and ORDER BY
- MySQL加密列MySQL encrypted columns