我对 mssql 的数据库查询有一个恼人的问题.如果结果包含像德语ä"这样的特殊字符,我将无法使用 json_encode 正确地将结果作为 json 获取.
I have an annoying problem with a database query to mssql. If the result contains special characters like the german 'ä', I cannot use json_encode to get the result as json correctly.
json_last_error 返回 5 等于 JSON_ERROR_UTF8.我猜数据库不会返回 UTF-8 编码的值.数据库集合是*Latin1_General_CI_AS*,受影响的列是varchars.
json_last_error return 5 which is equal to JSON_ERROR_UTF8. I guess the database does not return the values as UTF-8 encoded. The database collection is *Latin1_General_CI_AS* and the affected columns are varchars.
php mssql.charset 配置没有效果.
The php mssql.charset configuration has no effect.
我读到 mysql 用户可以使用 mysql_query('SET CHARACTER SET utf8'); 正确编码返回值.我该怎么做才能正确获取 mssql 的值?
I read that mysql users could use mysql_query('SET CHARACTER SET utf8'); to encode the return values correctly. What can I do, to get the values correctly for mssql?
提示 - 我无法更改数据库中的任何内容.
在 JSON 编码之前,在字符串周围使用 utf8_encode().
Before you JSON encode, use utf8_encode() around the string.
这篇关于json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 SELECT(MYSQL/PHP) 中加入 2 个表Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 个表)
如何使<option selected=“selected">由How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 设置?)
使用 PHP 中的数组自动填充选择框Auto populate a select box using an array in PHP(使用 PHP 中的数组自动填充选择框)
PHP SQL SELECT where like search item with multiple wordsPHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
MySQL ORDER BY rand(),名称 ASCMySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名称 ASC)
PDO 从数据库中获取数据PDO get data from database(PDO 从数据库中获取数据)