json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8)
问题描述
我对 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8


- PHP - if 语句中的倒序 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01