如何从包含外语的mysql获取数据?

时间:2018-06-27 11:07:06

标签: php mysql phpmyadmin

我正在一个项目中,我正在用外语存储数据 在MYSQL中。在数据库中时,自从我将归类设置为“ utf8-general-ci ”以来,它就可以了。 我可以毫无问题地查看它。但是,当我尝试将数据检索到 php 文档中时,它不起作用。我的代码是:

  <?php

    $servername = "localhost";
$username = "root";
$password = "";
$dbname = "31stknowledge";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


mysql_set_charset('utf8');
$sql = "SELECT * FROM course";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $Course = $row["Course"];
        $Duration = $row["Duration"];
        $Type = $row["Type"];
        $Description = $row["Description"];
        $Image = $row["Image"];
        header("Content-type: text/html; charset=utf-8");
         echo "<div class='col-lg-6 portfolio-item'>";
          echo "<div class='card h-100'>";
            echo "<a href='#'><img class='card-img-top' src='$Image' alt=''></a>";
            echo "<div class='card-body'>";
              echo "<h4 class='card-title'>";
                echo "<a href='#'>$Course</a>";
              echo "</h4>";
              echo "<p class='card-text'>$Description</p><br>";
              echo "<p class='card-text'>$Type</p><br>";
              echo "<p class='card-text'>$Duration</p><br>";
            echo "</div>";
          echo "</div>";
        echo "</div>";

    }
} else {
    echo "0 results";
}
$conn->close();
?>

谁能指出我的错误并引导我朝正确的方向发展?预先感谢。

0 个答案:

没有答案