在mysql中不在键盘上插入双引号和单引号

时间:2013-10-09 09:35:51

标签: php mysql

我试图插入除键盘之外的双引号

代表:

声明:阿什利正在读考试。在她的评论中,她指出“语义”表示“意义”,并思考这与语义记忆的关系。第二次审查显示她

插入mysql数据库后会转换为以下内容:

阿什利正在读考试。在她的评论中,她指出“语义”表示“意义”,并思考这与语义记忆的关系。甲

我已将所有表和数据库转换为utf-8排序规则,并且还为utf-8使用了元标记,但没有成功。有人可以确定问题。

1 个答案:

答案 0 :(得分:1)

我总是这样做:

$db = new mysqli('localhost','root','','db');
$cod = $db->query("SET NAMES 'utf8'"); //Set the encoding

这段代码对我有用(刚才):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ab</title>
<script type="text/javascript">


</script>
</head>

<body>
<?
$db = new mysqli('localhost','root','','test');
$cod = $db->query("SET NAMES 'utf8'");
$result = $db->query("INSERT INTO `test`(`string`) VALUES ('".addslashes("“teststring“")."')");
$result = $db->query("SELECT `string` FROM `test` WHERE string='".addslashes("“teststring“")."'");

$result= $result->fetch_assoc();
echo $result['string'];

?>
</body>
</html>
相关问题