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

标签 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_ä

echo 给出: 插入test ( car ) 值 ('越南_á»_法语_§_德语_¤ ')

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

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

我错过了什么?

最佳答案

也许在开始选择查询之前,您应该将查询设置为返回 UTF8 编码的字符串。首先,使用<meta charset="utf-8">在头部和查询之前尝试以下操作:mysqli_query($connection, "SET NAMES UTF8"); 。希望对您有所帮助。

关于php - 无法将语言特定字符写入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874556/

相关文章:

php - 从 HTML 屏幕打印动态页眉或页脚

php - 从本周获取条目?

mysql - 纪元时间和MySQL查询

vim - VIM 中的 UTF-8 编码

vim - 如何在 Vim 中对 UTF-8 行进行排序?

qt - 如何将 UTF-8 数据放入 QString

php - 在外部 JS 文件中传递 PHP 变量

php - 连接mysql数据库出错

php - 在 Gridview 函数 yii2 中访问变量

MySQL 一起使用 GROUP CONCAT 和 FIND_IN_SET