Aruna D Mahagamage
Aruna D Mahagamage

Reputation: 77

sinhala unicode in php

I have installed mysql and uploaded data to the database. When I view the data in phpadmin the unicode show fine.

1

In my php script I try to get the data from the database and it does not come in unicode but it shows up as in the below picture.

2

This is my php script. Please let me know where I have gone wrong.

 <?php
$servername = "localhost";
$username = "root";
$password = "xxxxx";
$dbname = "learnTV";


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


  //mysql_query ("set character_set_results='utf8'"); 

  $sql = "select l_id, t_id, net,file, dur, s_desc, e_desc, sex, name,       sin_desc from Lessons";
 $result = $conn->query($sql);

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


        echo "'" . $row["l_id"] . "','" .$row["t_id"] . "','" .$row["net"] .   "','" .$row["file"] . "','" .$row["dur"] . "','" .$row["s_desc"] . "','"  .$row["e_desc"] . "','" .$row["sex"] . "','" .$row["name"]. "','" .   $row["sin_desc"] . "----<br/>";
    }
  }  else {
      echo "0 results";
  }
  $conn->close();
   ?> 

Upvotes: 1

Views: 2109

Answers (2)

Aruna D Mahagamage
Aruna D Mahagamage

Reputation: 77

finally I solve above problem.

my solution is -

first set MYSQL appropriate db as a unicode.

then use this libraries in php scripts below DB connection.

mysqli_set_charset($conn,"utf8");

after that run php 

Upvotes: 2

Zaid Bin Khalid
Zaid Bin Khalid

Reputation: 763

You need to set unicode header using php.

header('Content-Type: text/html; charset=utf-8');

Upvotes: 0

Related Questions