JSON encoding

JSON encoding

nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
edited November 2012 in Editor
Hi,

When I type "André" as a value in my editor instance, it is saved as

André

in my mySQL table (UTF-8 encoding).

Why? Which type of encoding is used by datatables?

Kind regards,

Nathan

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    > Which type of encoding is used by data tables?

    Whatever your HTML page is using. Have you got the `charset="utf-8"` attribute on the `script` tag that includes DataTables and any other scripts? Also setting the HTML encoding explicitly would be a good idea.

    Allan
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Yes, I have set charset="utf-8" to all relevant JS and my HTML is encoded:


    The data displays correctly in Editor and Datatables, but is garbled in mySQL.

    E.g. André instead of André.

    What do you suggest? How is data encoded by the Editor PHP classes?
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    > How is data encoded by the Editor PHP classes?

    There is no special handling in the PHP classes - it should just pass the data straight through.

    Could you try adding the following to your PHP file (after you include the PHP bootstrap file but before you initialise the Editor class):

    [code]
    $db->sql("SET character_set_client=utf8");
    $db->sql("SET character_set_connection=utf8");
    $db->sql("SET character_set_results=utf8");
    [/code]

    That will force the socket connection to use UTF-8 as that sounds like it might be the weak point.

    Allan
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Bingo! That fixed it.
This discussion has been closed.