这是我的问题,我有一个阿拉伯数据库 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/