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

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

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)