I’m using an XMLHttpRequest for inserting some rows to a MYSQL database. I defined the relevant table columns to accept UTF-8 characters (Collation: utf8_general_ci).
The query being initiated from the request is:
INSERT INTO e4s_event_list (producerID, eventID, eventName, eventDescription, eventVenue, eventDate)
VALUES('2', 'f49c104b-6193-47b7-b196-ca914e5238c4', 'בכורה מאת שרון אייל וטאבולה ראסה מאת אוהד נהרין', '', 'Conversion Venue - 0', '2012-06-04T20:30:00')
If I query this from the phpMyAdmin the eventDescription column gets the desired value with no problem . But when the query being initiated from the XMLHttpRequest, the eventDescription column gets this value:
בכורה מ×ת שרון ×ייל וט×בולה..
My current headers are:
XMLHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XMLHttpRequest.setRequestHeader("Content-length", params.length);
XMLHttpRequest.setRequestHeader("Connection", "close");
I’ve tried to change Content-Type to:
XMLHttpRequest.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
But then, for some reason, the request doesn’t work at all.
I know it isn’t a database definition issue, because All other queries that aren’t initiated from an XMLHttpRequest are not being messed up.
How can I insert the Hebrew characters correctly ?
Thanks.
It’s possible that MySQL believes PHP is passing the string on as another character encoding (ISO-8859-1 for example). If that’s the case you can fix this by sending this query to MySQL before writing the data to the database: