日期:2014-05-17  浏览次数:20426 次

关于转码问题
import 503-9256962-4382268 Failure -1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '054-246-0787','JPS0001' ,'0243-BK', 'iphone 4 用臂帶 (黑色)', '1', '鷲??' at line 1

我进行了转码也报以上错误,我的转码函数:
$recipient_name=mb_convert_encoding(addslashes($u[16]), 'UTF-8','UTF-8,sjis-win,eucjp-win');



echo base64_encode($u[16])结果:mGiRg4xc

我输出转码后的结果是对的:"鷲巣圭",但是不知道写入数据库就会报错,我发现只有包含"圭"的都会写入数据库失败。

请问有什么办法解决这个问题??

------解决方案--------------------
$s = base64_decode('mGiRg4xc');
echo '字符集 ', mb_detect_encoding($s, 'UTF-8,sjis-win,eucjp-win'), '<br>';
echo '16进制内码 ', bin2hex($s), '<br>';
echo 'utf-8 ', $t = mb_convert_encoding($s, 'utf-8', 'UTF-8,sjis-win,eucjp-win'), '<br>';
echo '16进制内码 ', bin2hex($t);

字符集 JIS-win
16进制内码 986891838c5c 这个 5c 是 \ 的16进制内码
utf-8 鷲巣圭
16进制内码 e9b7b2e5b7a3e59cad

所以你需要
$recipient_name=mb_convert_encoding($u[16], 'UTF-8','UTF-8,sjis-win,eucjp-win');
而不是
$recipient_name=mb_convert_encoding(addslashes($u[16]), 'UTF-8','UTF-8,sjis-win,eucjp-win');
即不能用 addslashes 做转义处理

转义 ' 需要用 str_replace("'", "\'", $s)