mysql_query("set names utf8"); ZT]2008-05-02 11:46转自:http://www.phpchina.cn/bbs/viewthread.php?tid=60479 的第四楼
很久以前总结过一下,比较乱,有兴趣的话可以看看,感觉
关键是使用好set names 和文件编码(注意这个编码不是页面上的那个编码哦) 1.数据库 2.php文件 3.页面Mysql_query(“set names utf8”); Utf8与utf-8 全部用gb23121.
php文件可用dw修改—页面属性来改变成改变成gb23122.必须使用set nameUtf8是属于mysql数据库的Utf-8是属于页面的全部用utf8
1.只有使用了set names utf8后在sqlyog里面才能正常显示
 2.数据库编码如何选择都无所谓,只要用了set names+php文件编码正确就行!
3.用sqlyog和phpmyadmin之类的软件,如果没set names的话一定会乱码
4.如果set names与php文件编码不符的话就全世界都是乱码啦,无论数据库编码怎么设都不行 
数据库charset    数据表collection         php文件编码    页面编码    set names   输入      显示     Sqlyog显示
  gb2312             gb2312_chinese_ci     utf-8           utf-8      utf8      正常       正常     正常 gb2312              gb2312_chinese_ci     utf-8            utf-8     无         ??      ??     ??
gb2312              gb2312_chinese_ci     utf-8            utf-8      Gb2312     乱         乱         乱
 gb2312              gb2312_chinese_ci      utf-8         Gb2312     Gb2312      空白    空白    正常
 gb2312              gb2312_chinese_ci     Gb2312            Gb2312       Gb2312   正常  正常  正常
 gb2312              gb2312_chinese_ci       utf-8          Gb2312        Gb2312    ??   ??   ?? 数据库charset          数据表collection        php文件编码    页面编码    set names  输入 显示 Sqlyog显示
Utf8                utf8_unicode_ci          utf-8             utf-8        utf8       正常 正常 正常
 Utf8                 utf8_unicode_ci          utf-8         utf-8           无        正常 新输入的正常 新输入的乱
 Utf8               utf8_unicode_ci          utf-8          utf-8          Gb2312         乱 乱 乱
 Utf8               utf8_unicode_ci          utf-8          Gb2312           Gb2312         空白 空白 正常
 Utf8              utf8_unicode_ci          Gb2312          Gb2312           Gb2312         正常 正常 正常
 Utf8              utf8_unicode_ci          Gb23128        Gb2312          无        正常 新输入的正常 新输入的乱