在 MySQL 数据库中保存口音 [英] Save Accents in MySQL Database

查看:21
本文介绍了在 MySQL 数据库中保存口音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将法语口音保存在我的数据库中,但它们并没有像在数据库中那样保存.
例如,é"被保存为é".
我尝试将我的文件设置为Unicode (utf-8)",数据库中的字段是utf8_general_ci"以及数据库本身.
当我查看发布的数据时通过带有 Firebug 的 AJAX,我看到重音以é"的形式传递,所以它是正确的.

谢谢,让我知道您需要更多信息!


I'm trying to save French accents in my database, but they aren't saved like they should in the DB.
For example, a "é" is saved as "é".
I've tried to set my files to "Unicode (utf-8)", the fields in the DB are "utf8_general_ci" as well as the DB itself.
When I look at my data posted through AJAX with Firebug, I see the accent passed as "é", so it's correct.

Thanks and let me know you need more info!

推荐答案

我个人解决了同样的问题,在MySQL连接代码之后添加:

Personally I solved the same issue by adding after the MySQL connection code:

mysql_set_charset("utf8");

或用于 mysqli:

or for mysqli:

mysqli_set_charset($conn, "utf8");

或 mysqli OOP 等价物:

or the mysqli OOP equivalent:

$conn->set_charset("utf8");

有时您必须通过添加以下代码来定义主要的 php 字符集:

And sometimes you'll have to define the main php charset by adding this code:

mb_internal_encoding('UTF-8');

在客户端 HTML 端,您必须添加以下标题数据:

On the client HTML side you have to add the following header data :

<meta http-equiv="Content-type" content="text/html;charset=utf-8" />

为了使用 JSON AJAX 结果(例如通过使用 jQuery),您应该通过添加:

In order to use JSON AJAX results (e.g. by using jQuery), you should define the header by adding :

header("Content-type: application/json;charset=utf8");
json_encode(
     some_data
);

这应该可以解决问题

这篇关于在 MySQL 数据库中保存口音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆