无法将语言特定字符写入数据库

时间:2015-01-10 09:09:50

标签: php mysql utf-8

我需要在mysql数据库中保存带有特定语言字符的文本。 我用utf8_general_ci设置了表和字段 enter image description here

要写入数据库的test.php文件也在utf8_general_ci中:

<?php 

include 'connect.php';

$x=$_GET["x"];

$d="INSERT INTO `test` 
(`car`) 
VALUES (' $x ')";

echo $d;
$resultins = mysql_query($d);

echo mysql_error();
echo "<br>".$id;
?>

在浏览器中我做了:

/test.php?x=Vietnam_ờ_French_ç_German_ä

并且回声给出: INSERT INTO testcar)VALUES('Vietnam_á»_French_ç_German_ä')

在数据库中我得到: enter image description here

当我在另一个php中检索此数据并在浏览器中显示时,我得到: enter image description here

我错过了什么?

2 个答案:

答案 0 :(得分:1)

在启动select查询之前,您应该将查询设置为返回UTF8编码的字符串。首先,在头部使用<meta charset="utf-8">,在查询之前尝试:mysqli_query($connection, "SET NAMES UTF8");。希望它有所帮助。

答案 1 :(得分:-1)

在任何查询之前放置$ dbc-&gt; set-charset('utf8')。