在MySQL数据库中保存 [英] Save Accents in MySQL Database
问题描述
我尝试在数据库中保存法语口音,但它们不会像在数据库中一样保存。
例如,é保存为é 。
我尝试将我的文件设置为Unicode(utf-8),数据库中的字段是utf8_general_ci以及数据库本身。
当我查看我的数据通过AJAX with Firebug,我看到口音作为é传递,所以是正确的。
谢谢,让我知道你需要更多的信息!
<$> c $ c> mysql_set_charset(utf8);
或:
mysqli_set_charset );
或 POO :
$ mysqli_link-> set_charset(utf8);
有时候你需要定义 main php charset 此代码:
mb_internal_encoding('UTF-8');
必须添加以下标题数据:
< meta http-equiv =Content-typecontent =text / html ; charset = utf-8/>
为了使用JSON AJAX结果(例如通过使用jQuery),您应该通过添加:
header(Content-type:application / json; charset = utf8);
json_encode(
some_data
);
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!
Personally I solved the same issue by adding after the MySQL connection code :
mysql_set_charset("utf8");
or :
mysqli_set_charset("utf8");
or the POO equivalent :
$mysqli_link->set_charset("utf8");
And sometimes you'll have to define the main php charset by adding this code :
mb_internal_encoding('UTF-8');
On the client HTML side you have to add the following header data :
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
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
);
This should make the trick
这篇关于在MySQL数据库中保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!