MYSQL – Illegal mix of collations

February 22nd, 2012

<?php mysql_query(“SET NAMES ‘utf8′”); ?>

由於php mysql set utf8_general_ci, 但是在table column set左latin1_swedish_ci, 就會產生

#1267 – Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘like’

SELECT * FROM `table` WHERE `field` like ‘%這些%’

改成

SELECT * FROM `table` WHERE `field` like ‘%這些%’ COLLATE utf8_general_ci

Database, MYSQL, PHP, Program , ,