在MySQL数据库中存储波斯语\阿拉伯语文本 [英] Storing persian\Arabic text in mysql database

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

问题描述

我有一列昵称为它的集合为utf8-general-ci,表集合为UTF-8.但是波斯语/阿拉伯语文本存储在其中,如下所示.

I have a column with nickname that it's collection is utf8-general-ci and table collection is UTF-8. But persian/arabic text stores in it like below.

http://i.stack.imgur.com/CCWOa.png

应如何解决此问题?

我使用此代码进行保存

$sql = "INSERT INTO kashef_users(nickname ,username ,email ,ostan ,age ,gender ,sdk ,phonename ,imei ,time ) VALUES ".$data;

$data包含一个字符串,并且数据中的所有内容都是正确的

$data contains a a string and everything in data is correct

推荐答案

似乎您正在使用php填充$data.因此,您必须将字符集设置为UTF8(即SET NAMES 'utf-8';).例如,如果您使用的是mysqli,则代码将如下所示:

It seems you are using php to populate $data. So you have to set charset as UTF8 (i.e. SET NAMES 'utf-8';). For example if you were using mysqli, your code would be like this:

<?php
    $conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
    mysqli_set_charset($conn,"utf8");

或者如果您使用的是PDO此答案. com/a/16575294/1922137>已弃用的mysql .此外,不要忘记使用utf8-persian-ci集合.

Or use this answer if you were using PDO or this one for deprecated mysql. Moreover, do not forget to use utf8-persian-ci collection.

html中,如果您有表单,请将accept-charset设置为UTF-8:

In your html if you have a form, set the accept-charset as UTF-8:

<form action="" accept-charset="UTF-8">

这篇关于在MySQL数据库中存储波斯语\阿拉伯语文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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