php – how to fix mysql "Illegal mix of collations"-ThrowExceptions

Exception or error:

How do you fix a problem like this? Is the error in the code the server or in the database?

I’m using Laravel 5.2. the data i’m using is imported through a json api and inserted into a database.

production.ERROR: PDOException: SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_unicode_ci,COERCIBLE) for operation '=' in /home/forge/ 
How to solve:

You can workaround with php:

$t=mb_convert_encoding($t, 'UTF-8', 'UTF-8');

This will remove wrong encoded charaters

Leave a Reply

Your email address will not be published. Required fields are marked *