I've got REST api which returns tasks/companies/notes/etc. On localhost it works fine, no matter what task description or company name I write, but I put my app on server and when I'm using signs like "łźążćę" there is error Your data could not be encoded because it contains invalid UTF8 characters." at app/endor/jms/serializer/src/JMS/Serializer/JsonSerializationVisitor.php line 36
.
Databases are the same, tables too, all config options are the same. How can I fix this?
I had the same error when I use @VirtualProperty with method which cut string with substr(str, start, length) function. This function is bad choice if you use UTF8. Instead, use mb_substr.
I found a solution for this problem by setting the database connection properties to transfer data with UTF-8 charset. This is how the doctrine
section looks like in my app/config/config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: %database_driver%
dbname: %database_name%
user: %database_user%
host: %database_host%
password: %database_password%
charset: UTF8
options:
1002: "SET NAMES 'UTF8'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With