1

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();
   ?> 
  • See http://stackoverflow.com/a/38363567/1766831 - In particular, look at "Best Practice" and "Test the data". Your description does not quite follow any pattern there, so let us know the HEX and what you try and whether it works. (I hope you are using `CHARACTER SET utf8` or `utf8mb4`?) – Rick James May 09 '17 at 01:21
  • above 1 picture shows db view in phpmyadmin and 2 picture show after run php and that result. i try your instruction but not work. i added data using HTML UI and PHP to MySQL db . data is added and get back using php that fine work.but that moment problem is data store in unreadable form in MYSQL db. Please let me know where I have gone wrong – Aruna D Mahagamage May 09 '17 at 07:56
  • Please provide more details about what you did do -- how are you reading? What html code to display? Where did png#2 come from? What is in my.cnf? – Rick James May 09 '17 at 16:08

2 Answers2

2

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 
0

You need to set unicode header using php.

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

Zaid Bin Khalid
  • 748
  • 8
  • 25
  • above 1 picture shows db view in phpmyadmin and 2 picture show after run php and that result. i try your instruction but not work. i added data using HTML UI and PHP to MySQL db . data is added and get back using php that fine work.but that moment problem is data store in unreadable form in MYSQL db. Please let me know where I have gone wrong – Aruna D Mahagamage May 09 '17 at 07:57