I have a project developed in PHP 5.4.35 using CakePHP, When I insert some unicode string into database,
Example : Bệnh suy giảm trí nhớ
After insert into database, this is the database content of record :
Bệnh suy giảm trà nhớ
If I use php 5.4 it display perfectly on website :
Bệnh suy giảm trí nhớ
I also develop an api in json format for this project and the api response when I get this data is: B\u1ec7nh suy gi\u1ea3m tr\u00ed nh\u1edb When client (mobile client) get this data and display, it is displayed perfectly same as website.
But when I move to a hosting with php 5.3.23, it is displayed on website just like on database:
Bệnh suy giảm trà nhớ
And the api response : B\u00e1\u00bb\u2021nh suy gi\u00e1\u00ba\u00a3m tr\u00c3\u00ad nh\u00e1\u00bb\u203a It is dislayed : Bệnh suy giảm trà nhớ on mobile device (which displayed perfectly if I use php5.4 for api)
;
then I tried to use utf8_decode function of php after get it from database and this is result:
utf8_decode($record);
B��?nh suy giảm trí nh��?
I thought that maybe this string was encoded before inserted to mysql in php5.4 and then decoded right after get it from the database, but in php5.3 it keep the string when insert and get from database. and the encoder, decoder of utf8 in php 5.3 and 5.4 is different??? I guest.
I'm using cakephp 2.5.3 and it use PDO to insert and get data from database I've tried all the way to change charset, collate .... but it take no effect like : PDO -> exec ('SET names utf8'), PDO -> exec (' Set names utf8 collate utf8_unicode_ci'); .... I've also set the charset of header, html meta tags....
my database use utf8_unicode_ci collation in both environment no different in database version It's just I found no way to resolve the problem, so if anyone know about this please give me some solutions Thanks