Re: Cannot write utf8 data into a utf8 column - SOLVED [message #170752 is a reply to message #170747] |
Fri, 19 November 2010 16:25 |
Tony Marston
Messages: 57 Registered: November 2010
Karma:
|
Member |
|
|
"Peter H. Coffin" <hellsop(at)ninehells(dot)com> wrote in message
news:slrniebqgp(dot)1g0(dot)hellsop(at)abyss(dot)ninehells(dot)com...
> ["Followup-To:" header set to comp.databases.mysql.]
> On Thu, 18 Nov 2010 16:54:47 -0000, Tony Marston wrote:
>> This is very strange. When I try this update in my PHP program:
>>
>> UPDATE email_msg
>> SET size=771,
>> message_text='? ?:\n\n ????2010?11?25-26? ? ? ? 12?09-10? ? ?
>> ?12?16-17?
>> ?? ????:\n\n?
>> ????2010???????2011?????????????????????????
>> ????!\n\n?????????????????????????????????????????--?
>> ? ?? ??!\n\n\n????????????:baoming_gz(at)126(dot)com??! ( ?????????!)??!
>> \n\n\n\n?-?-?-?:0-2-0--3-9-9-2-6-2-7-5?(0)1-3-7-1-9-0-2-5-4-7-6
>> ???
>> ????\n\n?-?-?-?:baoming_gz(at)126(dot)com\n\n\n????????,?????"??"?"delete"?:tuidin01(at)163(dot)com
>> ??!',
>> revised_date='2010-11-18 15:48:09',
>> revised_user='AJM'
>> WHERE email_id='159'
>>
>> it fails with the following error:
>>
>> "Incorrect string value: '\xA0\xA0 \xE6\x88\x91...' for column
>> 'message_text' at row 1"
>>
>> When I try the SAME update through SQL-Front or phpMyAdmin it works! Why
>> is
>> this?
>
> If it were the SAME, it would work the same. MySQL gives this error when
> there's invalid UTF-8 byte sequences, like a continuation byte without
> starting byte, or a starting byte that is not followed by a continuation
> byte... Find out what the hex for what you're trying to stick in
> message_text and I bet it won't be what it should be.
The error message was reporting a problem with the hex value \xA0 (decimal
160) which represents ' ' or the non-breaking space. I discovered that
instead of replacing ' ' with chr(160) that I needed to replace it with
chr(194).chr(160). I don't now why the chr(194) is necessary, but it solves
my problem.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|