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


基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01