2008-02-26

mysql数据库字符集疑惑问题之FAQ

关键字: mysql, php, charset, 字符集
1. mysql_client_encoding()是干什么的?他存在哪些问题?

手册上说mysql_client_encoding
引用
Returns the default character set name for the current connection.

2. 他到底是返回character_set_server, character_set_system 系统变量的值,还是character_set_connect或character_set_client系统变量的值呢?
经过测试,以上全部是,不知道他返回的是哪个值。

3. 怎样修改他的返回值?

http://cn.php.net/manual/en/function.mysql-client-encoding.php上讨论得如火如荼,但是问题仍然没有解决:
引用
even if all your HTML/php source files are stored as 'utf-8' with header
<mata http-equiv="Content-type" content="type: text/html; charset=utf-8" />
and mysql server is everywhere UTF-8, adding 'set names "utf8"' and 'set character set "utf-8"' into your php to mysql connection,
you will always get the 'latin1' result by mysql_client_encoding();


如果你的php版本>= 5.2.3,会有这么一个函数,mysql_set_charset()它可以改变mysql_client_encoding的返回值。但这只是形式上的,实际上你不需要顾问这个返回值,只要
set names '你想要的字符集'
就可以了

4. set names 'charset' 和 set character set 'charset'有什么区别?

有一点区别,不过大多数情况下一样。
set names 'x'等价于:
SET character_set_client = 'x';
SET character_set_results = 'x';
SET character_set_connection = 'x';

而set character set 'x'等价于:
SET character_set_client = 'x';
SET character_set_results = 'x';
SET collation_connection = @@collation_database;
评论
angeltping 2008-03-25
你建数据库的时候可以指定为utf-8,以后建的表默认都是utf-8,对中文支持不错
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

xombat
搜索本博客
存档
最新评论