在MySQL中设置名称utf8? [英] SET NAMES utf8 in MySQL?
问题描述
我经常在使用MySQL的PHP脚本中看到类似的内容
query("SET NAMES utf8");
我从来没有对任何项目都这样做,所以我对此有两个基本问题.
- 这仅是通过PDO完成吗?
- 如果不是特定于PDO的事情,那么这样做的目的是什么?我意识到它正在为mysql设置编码,但是我的意思是,我从未使用过它,所以为什么要使用它?
每当您要将数据发送到服务器时,都无法将其用纯ASCII字符表示,例如ñ"或ö". >
如果默认情况下未将MySQL实例配置为期望客户端连接提供UTF-8编码(很多取决于您的位置和平台).
阅读 http://www.joelonsoftware.com/articles/Unicode.html 以防万一您不知道Unicode的工作原理.
阅读是否使用"SET NAMES" 来查看SET NAMES的替代方案和到底是什么.
I often see something similar to this below in PHP scripts using MySQL
query("SET NAMES utf8");
I have never had to do this for any project yet so I have a couple basic questions about it.
- Is this something that is done with PDO only?
- If it is not a PDO specific thing, then what is the purpose of doing it? I realize it is setting the encoding for mysql but I mean, I have never had to use it so why would I want to use it?
It is needed whenever you want to send data to the server having characters that cannot be represented in pure ASCII, like 'ñ' or 'ö'.
That if the MySQL instance is not configured to expect UTF-8 encoding by default from client connections (many are, depending on your location and platform.)
Read http://www.joelonsoftware.com/articles/Unicode.html in case you aren't aware how Unicode works.
Read Whether to use "SET NAMES" to see SET NAMES alternatives and what exactly is it about.
这篇关于在MySQL中设置名称utf8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!