Archive for ‘April, 2013’

Query error: Incorrect string value

datePosted on 16:39, April 20th, 2013 by yk

I was inserting records into a MySQL table using php and got an error that says:
Query error: Incorrect string value: '\xE2\x82...' for column 'message' at row 1 - Invalid query: INSERT INTO `my_table` (`message`) VALUES ('The price is xE2x82 500')

The original string in the ‘message’ field is actually
The price is € 500

This error is surprising given that the string is actually in UTF-8 encoding and the field in the MySQL table is declared as utf8_unicode_ci type.

The solution that I found it is to call the php function utf8_encode to encode string before inserting into the MySQL table.