Json_encode produces JSON_ERROR_UTF8 from MSSQL-SELECT

I have an annoying problem with querying a database to mssql. If the result contains special characters such as german 'Γ€', I cannot use json_encode to get the result as json correctly.

json_last_error return 5, which is equal to JSON_ERROR_UTF8. I think the database does not return UTF-8 encoded values. The database collection is * Latin1_General_CI_AS *, and the affected columns are varchars.

The php configuration of mssql.charset is not affected.

I read that mysql users can use mysql_query('SET CHARACTER SET utf8'); to properly encode return values. What can I do to get values ​​for mssql correctly?

Hint - I cannot change anything in the database.

+6
source share
1 answer

Before JSON encoding, use utf8_encode() around the string.

+11
source

Source: https://habr.com/ru/post/951783/


All Articles