PHP MYSQL用阿拉伯语插入数据 [英] PHP MYSQL Insert Data in Arabic Language
问题描述
我正在尝试使用PHP和HTML表单将一些阿拉伯语数据插入MySQL.当我将数据插入到MYSQL表中时,表字段将数据表示为مرØبا العالم
.
I am trying to insert some Arabic Language data into MySQL using PHP and an HTML form. When I insert the data in to MYSQL table, the table field represents data as مرØبا العالم
.
但是,当我使用PHP访问相同的数据并将其显示在网页中时,它会显示正确的数据.我正在使用:
But when I access the same data with PHP and show it in my webpage, it shows the correct data. I am using:
http-equiv="Content-Type" content="text/html; charset=utf-8"
我的网页中的
meta
标签显示阿拉伯数据.我的问题是为什么我的数据看起来像这样:MySQL表中的مرØبا العالم
,以及我应该如何纠正它.
meta
tag in my web page to show Arabic data. My question is why my data looks like this: مرØبا العالم
in MySQL table, and how should I correct it.
推荐答案
您必须执行以下两项操作:
You have to do both of the following:
- 确保您的数据库编码和排序规则为
utf8_general_ci
(用于字段本身,表以及数据库). -
在建立与数据库的连接后立即发送两个命令:
- Make sure your database encoding and collation is
utf8_general_ci
(both for the field itself and the table as well as the database). Send two commands right after establishing a connection to the database:
mysql_query("SET NAMES utf8;");
mysql_query("SET CHARACTER_SET utf8;");
这篇关于PHP MYSQL用阿拉伯语插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!