SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (gb2312_chinese_ci,COERCIBLE) for operation ‘=’
在操作MySQL数据库时,报“
error code [1267];
在Mysql数据库中执行函数报错:
Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘like’
对于常见的乱码问题,有的在数据库本身已经为gbk或gb2312时候,但是查询出来却是乱码,这是因为mysql在连接的过程中还有道编码,因此将连接的编码设为gb2312或utf-8
即可,如:
jdbc:mysql://localhost:3306/ipanel?useUnicode=true&characterEncoding=UTF-8
最重要的是这个问题:
Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (gb2312_chinese_ci,IMPLICIT) for operation ‘=’
是数据库内部的编码不统一引起的:
gbk_chinese_ci,有的数据是gb2312_chinese_ci,因此解决此问题的核心就是将数据库所有的编码进行统一。
解决方案一:暂时
//恶心的gb2312不能使用,需要转utf-8再继续
$where = $where . iconv(“gb2312”,“utf-8”," and USE