此PHP代码上不显示Bangla字体

时间:2015-12-12 09:18:20

标签: php mysql

这是一个PHP代码

PHP

<?php
  $servername = "server";
  $username = "user";
  $password = "password";
  $dbname = "db";



  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection

  if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  } 

  $sql = "SELECT idbn, infobn, datebn FROM `update`";
  $result = $conn->query($sql);


  if ($result->num_rows > 0) {
      // output data of each row
      while($row = $result->fetch_assoc()) {


  echo "<tr><td><a> ";
  echo  $row["idbn"];
  echo "</a></td><td><a> ";
  echo $row["infobn"];
  echo "</a></td><td><a>" . $row["datebn"]. "</a></td></tr>";
    }
  } else {
      echo "0 results";
  }
  $conn->close();
  ?>

但问题是,它没有从mysql中检索孟加拉语数据

mysqli_query('SET CHARACTER SET utf8');
mysqli_query(“SET SESSION collation_connection ='utf8_general_ci'") or die (mysql_error());

我还在这里添加了这段代码。但每次丢失数据。如果我删除UTF8代码,那么我得到?????。所以我需要帮助。

1 个答案:

答案 0 :(得分:1)

我猜你的问题是与utf8连接到db。

1)在utf8_general_ci

中使用您的数据库列

2)设置mysqli连接以使用utf8

$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
$mysqli->set_charset("utf8")

点击此处:http://php.net/manual/en/mysqli.set-charset.php