php - php 和 mysql 上的阿拉伯字符 "???????"

标签 php mysql mysqli


这是我的问题,我有一个阿拉伯数据库 mysqli UTF8_general_ci 并且我的 php 文件的字符集是 UTF-8 当我出售数据时,我得到“????????????”。
在 php 上,我的管理员我可以毫无问题地写入和读取,在 php 上我也可以,但问题是当我从数据库获取数据时!这是我的代码:

<meta charset="UTF-8"/>

$connexion = new mysqli(HOST_DB,USER_DB,MDP_DB,DB_NAME);
        if ($connexion->error) {
            die('Une erreur s\'est produite :' .$connexion->error);
        }
        else{
            $sql = "SELECT nom, description, date, formateur, image, prix, lieux FROM news";
            if ($result = mysqli_query($connexion,$sql)) {
                while ($ligne = mysqli_fetch_assoc($result)) {
                    echo'
                        <ul>
                            <li><figure>
                                <figcaption>
                                    <h1>'.$ligne["nom"].'</h1>
                                    <p>'.$ligne["description"].'</p>
                                    <strong>اليوم:'.$ligne["date"].'</strong><br/>
                                    <strong>المكان:'.$ligne["lieux"].'</strong><br/>
                                    <strong>المدرس:'.$ligne["formateur"].'</strong><br/>
                                    <strong>الثمن: '.$ligne["prix"].'دينار</strong>
                                    </figcaption>
                                <img src="Images/'.$ligne["image"].'" height="250px" width="250px">
                            </figure></li>
                        </ul>
                    ';
                }
            }
        }

最佳答案

将此代码放在连接mysql之后。 mysqli_set_charset($connexion,'utf8'); 这是连接数据库的最终代码: $connexion = new mysqli(HOST_DB,USER_DB,MDP_DB,DB_NAME); mysqli_set_charset($connexion,'utf8');

关于php - php 和 mysql 上的阿拉伯字符 "???????",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21604657/

相关文章:

php - 是否可以在 mysql 中选择 SET 的所有单个字符串?

php - Android 应用程序向 mysql 数据库添加数据会抛出 JSONException

mysql - 显示 html 时遇到问题

php - 仅向用户显示数据库中的记录一次

php - 如何在没有 cpanel 访问权限的情况下导出 mysql 数据库

javascript - 如何检测Android浏览器而不是Android应用程序(WebView)?

php - ldap_搜索() : Search: Operations error again

PHP CodeIgniter 外部 API 调用

php - 如何检查 mysql 表的 bool 字段以及在 php 中将 0 或 1 值转换为 true/false

mysql - SAS MYSQL libname 连接问题