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我输出转码后的结果是对的:"鷲巣圭",但是不知道写入数据库就会报错,我发现只有包含"圭"的都会写入数据库失败。请问有什么办法解决这个问题??

解决方案 »

  1.   

    $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) 
      

  2.   

    xuzuning 大大:
         不转义可以了 ,不过有个问题还想请教一下,因为我插入的内容是很多国家的,如果不转义的话,不知道哪个国家的人名里面包含一些特殊,不转义的话有可能一样写入失败,请问这种情况有办法解决吗?