Maison >développement back-end >tutoriel php >SET NAMES UTF8的具体作用是什么?
为了防止乱码,我在为db设罢了好几个字符集:
<code> mysqli_query($db,"SET NAMES UTF8"); mysqli_query($db,"set character_set_client=utf8"); mysqli_query($db,"set character_set_connection=utf8"); mysqli_query($db,"set character_set_results=utf8");</code>
不过看到一个文章是这样说的:
http://zhangxugg-163-com.iteye.com/blog/1835721
按上面的描述,一条SET NAMES UTF8
是不是就已经等于set character_set_client=utf8; set character_set_connection=utf8; set character_set_results=utf8;
这三条呢?
大家讨论下
.`
为了防止乱码,我在为db设罢了好几个字符集:
<code> mysqli_query($db,"SET NAMES UTF8"); mysqli_query($db,"set character_set_client=utf8"); mysqli_query($db,"set character_set_connection=utf8"); mysqli_query($db,"set character_set_results=utf8");</code>
不过看到一个文章是这样说的:
http://zhangxugg-163-com.iteye.com/blog/1835721
按上面的描述,一条SET NAMES UTF8
是不是就已经等于set character_set_client=utf8; set character_set_connection=utf8; set character_set_results=utf8;
这三条呢?
大家讨论下
.`
<code>set NAMES utf8 show variables like "character_set_%"</code>
操作显示是这样的
如上回答,改变了character_set_client/character_set_connection/character_set_results三个值
是的,一条命令等于你所列的3条,主要确保编码一致性不乱码