插入阿拉伯文字MySQL [英] Insert an Arabic text MySQL
问题描述
我正在尝试将阿拉伯文本存储到表中,我进行了很多搜索,但没有找到适合我的解决方案,所以这就是我得到的:
I'm trying to store an Arabic text to the table, I searched a lot but I didn't find a solution that worked for me, so this is what I got:
$en = "OK";
$ar = "حسناً";
$link->query("INSERT INTO words (en,ar) VALUES ($en,$ar)");
问题是当我插入它时,阿拉伯文本看起来像Øسناً
,我的表的排序规则和MySQL的是utf8_general_ci
,数据库的也是,我也有mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');
,但是它不起作用. /p>
The problem is when I insert it, the Arabic text looks like Øسناً
, my table's collation and MySQL's are utf8_general_ci
, so is my database's, I also have mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');
, but it doesn't work.
推荐答案
我最近也遇到了同样的问题.
I recently had the same issues myself.
以下是一些提示:
- 所有属性必须设置为ut8(排序规则与charset不同)
- 将文档另存为UTF-8(如果使用的是Notepad ++,则其格式为->转换为UFT-8)
- PHP和HTML中的标头都应设置为UTF-8(HTML:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
和PHP:header('Content-Type: text/html; charset=utf-8');
- 在连接到数据库之后,也将字符集设置为ut UTF-8,如下所示:
$link->set_charset("utf8");
(连接后直接) - 还要确保将数据库和表设置为UTF-8,您可以这样做:
- ALL attributes must be set to ut8 (collation is NOT the same as charset)
- Save the document as UTF-8 (If you're using Notepad++, it's Format -> Convert to UFT-8)
- The header in both PHP and HTML should be set to UTF-8 (HTML:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and PHP:header('Content-Type: text/html; charset=utf-8');
- Upon connecting to the databse, set the charset ti UTF-8 there as well, like this:
$link->set_charset("utf8");
(directly after connecting) - Also make sure your database and tables are set to UTF-8, you can do that like this:
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
请记住,一切都必须设置为UFT-8字符代码,否则它将插入诸如Øسناً"之类的内容.希望这会有所帮助!
Remember that EVERYTHING needs to be set to UFT-8 charcode, or else it'll insert stuff like "Øسناً". Hope this helped!
这篇关于插入阿拉伯文字MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!