在 MySQL 数据库中保存口音

Save Accents in MySQL Database(在 MySQL 数据库中保存口音)
本文介绍了在 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 数据库中保存口音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)