使用php将阿拉伯语文本存储在mysql数据库中

Store Arabic text in mysql database using php(使用php将阿拉伯语文本存储在mysql数据库中)
本文介绍了使用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

有什么建议吗?

推荐答案

奇怪,它应该管用!

在成功连接到数据库后尝试添加这些行:

Try adding these lines after a successful connection to the database:

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


例如:

$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");
}


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


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数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Warning: mysqli_query() expects at least 2 parameters, 1 given. What?(警告:mysqli_query() 需要至少 2 个参数,1 个给定.什么?)
INSERT query produces quot;Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean givenquot;(INSERT 查询产生“警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,给出布尔值;)
prepared statements - are they necessary(准备好的陈述 - 它们是否必要)
Do I need to escape my variables if I use MySQLi prepared statements?(如果我使用 MySQLi 准备好的语句,是否需要转义我的变量?)
Properly Escaping with MySQLI | query over prepared statements(使用 MySQLI 正确转义 |查询准备好的语句)
Is it possible to use mysqli_fetch_object with a prepared statement(是否可以将 mysqli_fetch_object 与准备好的语句一起使用)