0

I'm pulling data from a database and rearranging it in a associative array. I'm using MySQL, the db collation is utf8_general_ci.

On my development machine, when I echo json_encode($data), everything works perfectly

I imported the database onto my server, all of the same scripts etc... However, for only some results, json_ecode returns nothing, upon investigation,

echo json_last_error() === JSON_ERROR_UTF8;

returns 1.

I don't really know how to further debug, does anybody have any pointers as to what is going on here?

EDIT

I don't see how this is a duplicate, I understand the use of utf8_encode... The fact that it is working differently on separate systems is confusing me and any help would be much appreciated.

SECOND EDIT

A working example is not necessary to show that utf8_encode is needed, as it was not the correct solution. The dev mysql server was configured differrently than the remote mysql server.

The solution that worked for me was editing /etc/mysql/my.conf

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

I would gladly answer this question if it were reopened.

Dave
  • 723
  • 7
  • 19
  • 3
    Well it seems that your database is returning UTF-8 encoded data on one system and something else on another. There are apparently differences in configuration there. Have you checked http://stackoverflow.com/questions/279170/utf-8-all-the-way-through? – deceze Mar 03 '15 at 10:01
  • Please compare `phpinfo()` between the machines: http://php.net/manual/en/function.phpinfo.php escpecially anything to do with mysql and encoding. For example gentoo linux allows you to specify "client encoding" in mysql.cnf but other linux distros don't. – Dima Tisnek Mar 03 '15 at 10:47
  • @Dave to revive the question, please post minimal working example (php source) that demonstrates you've handled unicode/utf8 issue already. – Dima Tisnek Mar 03 '15 at 10:48
  • @deceze This pointed me in the right direction, I'll answer my question. – Dave Mar 04 '15 at 00:39
  • @qarma Like I said in the edit, utf_encode wasn't the solution, as it was working correctly on one computer. Thus, it is not a duplicate of the question indicated. – Dave Mar 04 '15 at 00:41
  • Btw., you most likely want utf8mb4: http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html – Dima Tisnek Mar 04 '15 at 08:18

0 Answers0