2017-03-01 152 views
0

我有一个数据编码问题。我的数据库在其中一列中有口音,在api中返回一个PDO查询SQL SERVER中的列。只要我返回,我通过json_encode方法转换成JSON,再加上JSON就是NULL。当我给var_dump带有重音符号的问号时,这个字符会出现' ',而json是空的。 我知道这是我需要转换为UTF8的编码,但我无法在php中进行此转换。谁能帮我?返回JSON NULL

enter image description here

+0

帮助吗? http://stackoverflow.com/questions/16800915/php-pdo-charset-utf8-an-invalid-keyword-charset-was-specified-in-the-dsn-str –

+0

尝试'utf_encode()'并检查。你能否也请告诉那里的原始人物是什么? –

+0

<?php ini_set('display_errors',1); ini_set('display_startup_errors',1); include_once'../../../config.php'; include_once'../../../config.php'; include_once'../api/helpdesk.php'; include_once'../api/conexaoSql.php'; require_login(); $ codigo = $ _GET ['id']; 尝试{ $ objHelp = new helpdesk(); $ mensagens = $ objHelp-> SelecionaMensagem($ codigo); // var_dump($ mensagens); echo json_encode($ mensagens,JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ($ e-> getMessage());}};}};}}; } –

回答

-2

你指定的字符集权的头?

header('Content-type: text/html; charset=utf-8');

还请注意,您的列和表应该是utf8_unicode_ci

最后你的连接到数据库也应该相应地设置charset=utf8

+0

在发布我的答案后不到1秒钟,就低估了我:非常感谢。 – Ditto

+0

不客气。这个问题与Content-type:text/html无关。与MySQL无关。 –

+0

@YourCommonSense你在不到1秒的时间内看到了这一切。凉。 – Ditto