$db->execute("insert db2.testimg (`img`) values ("$img") ;"); 报错: 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 "`?绶q?仳!????1丶>,Mo?"^WZ4in??T春??????U?楹?" at line 1 代码如下: 复制代码 代码如下:$img = fread($fp, filesize($fileName)); $img = addslashes($img) 继续报错,各种搜索,百度里的结果都是addslashes,要不就是addslashes也没有的,真是扯淡啊. 复制代码 代码如下:base64_decode $img = base64_encode($img); 插入成功,图片文件17.0k,出来进行base64_decode,显示正常,找到个16进制的办法: 复制代码 代码如下:$img = bin2hex($img); 有效,输出不用解密,存入数据库很大 25K,比base64还坑爹呢,再找,后来,后来,发现phpmyadmin直接上传的图片文件可以用文件比base64的小,文件12.8k. 翻phpmyadmin 源代码,common.lib.php文件183有个神奇的函数,代码如下: 复制代码 代码如下:function PMA_sqlAddslashes($a_string = "", $is_like = false, $crlf = false, $php_code = false) { if ($is_like) { $a_string = str_replace("", "\\", $a_string); } else { $a_string = str_replace("", "\", $a_string); }