failed to insert BLOB data on multibyte charset

i'm using GBK charset. mysql 4.01
use PHP to insert, did addslashes before insert
however, failed.

i've read the mysql_escape_string() source code. noticed that, mb char is 
processed differently, but is it a must ?
yes, php+libmysql is not up to date, but i'm trying to use my own escaping 
function

function &GBK_escape_string($data)
{
        $ret = '';
        $l = strlen($data);
        for ($i = 0; $i < $l; $i ++)
        {
                $c = ord($data{$i});
                if (0x81 <= $c && $c <= 0xfe && ($i+1) < $l)
                {
                        $c2 = ord($data{$i+1});
                        if ((0x40<=$c2 && $c2<=0x7e) ||
                                (0x80<=$c2 && $c2<=0xfe))
                        {
                                $ret .= $data{$i};
                                $ret .= $data{++$i};
                                continue;
                        }
                }
                
                switch ($data{$i})
                {
                case "\\": $ret .= "\\\\"; break;
                case "\0": $ret .= "\\0"; break;
                case "\n": $ret .= "\\n"; break;
                case "\r": $ret .= "\\r"; break;
                case "'": $ret .= "\\'"; break;
                case "\"": $ret .= "\\\""; break;
                case "\032": $ret .= "\\Z"; break;
                default: $ret .= $data{$i}; break;
                }
        }
        return $ret;
}

still won't work
anyone could give me a hand?


i'm supposing the error:

string: ....\n\xE0'".....
according to ctype-gbk.c ismbchar_gbk
\xE0' is not mbchar, \xE0 should not escape, and ' should escaped.
result: ....\x5Cn\xE0\x5C'\x5C"..... (0x5C is backslash)
when mysqld scanning this string
\x5Cn is scan as \n, correct
but \xE0\x5C is scan as a GBK char, then ' will be a string terminator
and complain that
SQL syntax near '\"'
which is the escaped double-quote ...0x5C"...


_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: 
http://messenger.microsoft.com/cn/


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to