0
I am making a query in a sqlserver database with PHP/PDO then return a JSON to search in Angular JS.
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($result);
print $json;
However, the values it contains, for example:
string(17) "Iniciou Inscri��o"
In JSON it returns as null
. My possible solutions, includes:
header('Content-Type: application/json; charset=utf-8');
json_encode($result, JSON_UNESCAPED_UNICODE)
None of them solved it. Someone has a solution ?
Please insert "inscrição" instead of "inscription". If it happens what I think I already give you a solution
– Miguel
I couldn’t understand it. I’m looking for it directly in the database.
– system333
Yes I know, I’ve had this problem too, it’s because it shouldn’t be set to utf-8
– Miguel
So, I change this directly in the database ? It’s not just that phrase. There are several. In the database you are searching right, but when I search directly in php, it brings with these questions.
– system333
Just one, to test. In that same word, change to what I told you above
– Miguel
It did not work, he returned me inscrição.
– system333
Looks like you really have to
mysql_query("SET NAMES 'utf8'");
in its database, http://stackoverflow.com/questions/18009075/php-output-json-web-service-charset-utf-8-error– Miguel
I am using PDO and this command does not work on SQL Server.
– system333
Usually I go through the record by adding the value in a new array, where the value deal with utf8_encode. This is because the database is ISO and the return of JSON and UTF8.
– Mayron Ceccon