kit*_*ski 1 mysql insert special-characters
我正在将大量信息从XML文件写入数据库.
一切正常,直到我遇到一个带有'在描述中的字段,插入失败并出现错误
Run Code Online (Sandbox Code Playgroud)Error 1064:You have an error in your SQL syntax; check the manual that对应你的MySQL服务器版本,使用正确的语法,让你感觉就像这样.我们很乐意让您访问我们,在第3行查看超过100'
有没有办法插入它而不失败?导入文件可能很大并且会定期更改,因此我无法搜索和替换其中的字符.
我的实际PHP声明是:
$query = mysql_query("REPLACE into list
(id, name, link, description, cost, date_added,type,myipaq,private,imgurl)
VALUES ('$id','$name','$link',"'$description'",'$cost','$date','$type','$myipaq','$private','$imgurl')");
Run Code Online (Sandbox Code Playgroud)
提前致谢,
格雷格
这属于SQL注入的范畴.
在PHP中有一个函数:mysql_real_escape_string用于对字符串进行编码,这样它就不会影响它可能连接成的SQL语句.
所以确保你的所有值都通过mysql_real_escape_string函数,你会没事的.
API REF:http://php.net/manual/en/function.mysql-real-escape-string.php