PHP MYSQL 插入阿拉伯语数据 [英] PHP MYSQL Insert Data in Arabic Language

查看:35
本文介绍了PHP MYSQL 插入阿拉伯语数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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:

  1. 确保您的数据库编码和排序规则是 utf8_general_ci(对于字段本身、表以及数据库).
  2. 在与数据库建立连接后立即发送两个命令:

  1. Make sure your database encoding and collation is utf8_general_ci (both for the field itself and the table as well as the database).
  2. 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屋!

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