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

查看:89
本文介绍了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天全站免登陆