从mysql数据库中读取特殊字符

时间:2013-09-30 09:47:13

标签: php mysql sql

我正在尝试从我的数据库中读取uft-8 unicode到我的网页上。

编码(根据数据库):utf8_unicode_ci(使用000webhost)

字段的内容:! http://puu.sh/4DY1O.png如您所见,第二个单元格末尾包含“é”。当我通过SQL查询读出来时,我在我的网站上得到了这个:http://puu.sh/4DY4t.png

这是我正在使用的查询:

// Create connection
   $con = mysqli_connect("host","username","passwd","database");

// Database Connection Check
   if (mysqli_connect_errno($con)) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      break;
   }

   // Print Ploegsamenstelling
      // Print Spelers
         $result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolLeden WHERE ploeg_id='5' ORDER BY voornaam, naam");
         while($row = mysqli_fetch_array($result)) {
            echo "<dt>" . $row['voornaam'] . " " . $row['naam'] . "</dt>";
         }
         echo "<br />";
      //Print Trainer
         $result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolTrainers WHERE ploeg_id='5'");
         while($row = mysqli_fetch_array($result)) {
            echo "<dt><strong>Trainster: </strong>" . $row['voornaam'] . " " . $row['naam'] . "</dt>";
         }

// Close Connection
mysqli_close($con);

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

这是我的头脑:)用您在服务器上使用的字符集替换YOURCHARSET :(使用Iconv

 $result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolLeden WHERE ploeg_id='5' ORDER BY voornaam, naam");
$naam = iconv("UTF-8", YOURCHARSET HERE, $row['naam'])
$voornaam = iconv("UTF-8", YOURCHARSET HERE, $row['voornaam'])
while($row = mysqli_fetch_array($result)) {
    echo "<dt>" .$voornaam . " " . naam  . "</dt>";
}
echo "<br />";
//Print Trainer
$result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolTrainers WHERE ploeg_id='5'");
$naam = iconv("UTF-8", YOURCHARSET HERE, $row['naam'])
$voornaam = iconv("UTF-8", YOURCHARSET HERE, $row['voornaam'])

while($row = mysqli_fetch_array($result)) {
    echo "<dt><strong>Trainster: </strong>" .$voornaam. " " . $naam . "</dt>";
}