Shuvo Shuvo
Shuvo Shuvo

Reputation: 329

Bangla font is not displaying on this PHP code

Here is a PHP code

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();
  ?>

But the problem is, it is not retrieving the Bengali data from mysql

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

I also added this code here. But every time it lost the data. if I remove the UTF8 code then I got ?????. So I need help out of this.

Upvotes: 1

Views: 3059

Answers (2)

Liton Mazumder
Liton Mazumder

Reputation: 21

This one worked for me. Try this code below.

public function __construct()
    {
        $hostname = "hotname";
        $username = "username";
        $password = "password";
        $database = "database_name";

        $this->link = mysqli_connect($hostname, $username, $password, $database);
        mysqli_set_charset($this->link, "utf8");
    }

Upvotes: 0

Armen
Armen

Reputation: 4202

I guess your problem is with utf8 connection to db.

1) make use your db column in utf8_general_ci

2) set mysqli connection to use utf8

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

Check here: http://php.net/manual/en/mysqli.set-charset.php

Upvotes: 2

Related Questions