$q = $this->createQuery('q')
->where('q.group_id=?', $group_id)
->andWhere('q.content=?', $content)
->execute();
If my $content contains any unicode characters (e.g. Chinese/japanese) this cau开发者_C百科ses the following message:
SQLSTATE[HY000]: General error: 1267 Illegal mix of collations
(latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
Any one encountered similar problem before?
You can use the COLLATE function with MySQL in the where clause, will need to convert the inbound data to the column collation (latin1_swedish_ci)
$q = $this->createQuery('q')
->where('q.group_id=?', $group_id)
->andWhere('q.content = _latin1 ? COLLATE latin1_swedish_ci', $content)
->execute();
For details about the collate function you can have a look at http://dev.mysql.com/doc/refman/5.6/en/charset-collate.html which has the details, this have been in mysql from 4.1.
You can also set the collation per column as well in the definition of the table structure (see http://dev.mysql.com/doc/refman/5.6/en/charset-column.html) for details.
Hope this helps.
精彩评论