4
$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 causes 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?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
whamsicore
  • 8,320
  • 9
  • 40
  • 50

1 Answers1

1

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.

Payload
  • 1,686
  • 1
  • 10
  • 6