我目前遇到这个问题,我使用 mysqlescapestring 将数据插入到我的数据库中,并且在检索数据时包含许多冗余 / 字符。有没有办法扭转这种情况?
这是我的代码
$post_nameE = EscapeString($post_name);
$post_descE = EscapeString($post_desc);
$post_dateE = date("Y-m-d H:i:s");
$post_contentE = EscapeString($post_content);
$statusE = EscapeString($status);
$tagE = EscapeString($tag);
$sql="INSERT INTO post (post_id, post_name, post_desc, post_date, post_content, status, tags)
VALUES (DEFAULT, '$post_nameE', '$post_desc', '$post_dateE', '$post_contentE', '$statusE', '$tagE' )";
$res = dbQuery($sql);
if ($res)
echo "1 record added";
else
die('Error: ' . mysqli_error($res));
和转义字符串定义:
function EscapeString($s) {
global $mysqli;
return $mysqli->real_escape_string($s);
}
内容:
'The ice bucket challenge'
从数据库中检索并显示的内容:
\'The ice bucket challenge\'
我一直在阅读其他 stackoverflow 问题,大多数人声称这不应该发生,是否有解决方法?