插入阿拉伯语文本 MySQL [英] Insert an Arabic text MySQL

查看:42
本文介绍了插入阿拉伯语文本 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');,但它不起作用.

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(排序规则与字符集不同)
  • 将文档另存为 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');
  • 连接到数据库后,在那里也设置字符集 ti 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;

请记住,一切都需要设置为 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屋!

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