使用php在mysql数据库中存储阿拉伯语文本 [英] Store Arabic text in mysql database using php

查看:114
本文介绍了使用php在mysql数据库中存储阿拉伯语文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个mysql数据库中存储一些阿拉伯语数据
我已经将html文档字符集设置为'utf8'

I am trying to store some Arabic data in a mysql database I have set the html document charset to be 'utf8'

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

MySQL字符集设置为:UTF-8 Unicode(utf8)

MySQL charset is set to: UTF-8 Unicode (utf8)

MySQL连接排序规则设置为:utf8_general_ci

MySQL connection collation is set to: utf8_general_ci

数据库和表排序规则设置为:utf8_general_ci

Database and table collations are set to: utf8_general_ci

此外,在我的PHP代码中,我使用 $ mysqli-> set_charset(utf8)函数来确保字符集设置为ut8,实际上是工作,我使用html形式发布我的数据到php脚本其中enctype是: enctype =multipart / form-data因为在这种形式我还上传一个图像

In addition in my php code I used the $mysqli->set_charset("utf8") function to ensure that the charset is set to be ut8 but nothing is actually working , I am posting my data to the php script using html form where the enctype is : enctype="multipart/form-data" because in this form I also upload an image

奇怪的是,当我直接在mysql中写我的查询时,阿拉伯字符存储正确,没有问题,但是当我使用php查询来存储数据所有字符存储在错误的字符集编码中

The weird thing is that when I write my query directly in mysql the Arabic characters are stored properly with no problem , but when I use a php query to store the data all the characters are stored in a wrong charset encoding

有任何建议吗?

推荐答案

很奇怪,它应该可以工作!

Weird, It should work!

成功连接到数据库后:

$mysqli->query("SET NAMES 'utf8'");
$mysqli->query("SET CHARACTER SET utf8");



例如:


For example:

$mysqli = @new mysqli('DB_HOST', 'DB_USER', 'DB_PASS', 'DB_NAME');

if($mysqli->connect_errno) die('Connection Error!');
else{
    $mysqli->query("SET NAMES 'utf8'");
    $mysqli->query("SET CHARACTER SET utf8");
}



并在头部包含这些META标签您的php页面:


And include these META tags in the head section of your php page:

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

这篇关于使用php在mysql数据库中存储阿拉伯语文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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