1

I am retrieving data in Indian language and I am getting output as ??????????????????????????

NOTE : - I used this 2 line in my php script

header('Content-type: text/plain; charset=utf-8');
mysqli_set_charset($conn,'utf-8');

and also I used utf8_general_ci encoding in databse and table.

my php script is

<?php

require 'init.php';

header('Content-type: text/plain; charset=utf-8');
mysqli_set_charset($conn,'utf-8');

$table = $_GET['table_name'];

$sql = "SELECT * FROM ".$table;

$response = array();

$result = mysqli_query($conn,$sql);

if(mysqli_num_rows($result)>0) {
        while($row = mysqli_fetch_array($result)) {
        array_push($response, array('id'=>$row['id'],'text'=>$row['text']));
    }
    echo json_encode($response);
} else {
    echo "error";
}

mysqli_close($conn);

?>

You can check the link http://www.sharefb.com/statusApp/readStatus.php?table_name=gujrati_attitude

  • 2
    **WARNING**: When composing queries **DO NOT** use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST`, `$_GET` or **any** user data directly into a query, it can be very harmful if someone seeks to exploit your mistake. You must test that table name against a list of known-good values or you're wide open to attacks, errors, or worse. – tadman Jul 04 '17 at 06:28

3 Answers3

0

Use mysqli_set_charset( $db, 'utf8');

Rajesh N
  • 6,198
  • 2
  • 47
  • 58
  • I used this too..but didn't worked...can't you see in the question description. Please read the question nicely before answering. – Gaurav Bordoloi Jul 04 '17 at 06:45
0

Add this meta tag in header and try

<META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="utf-8" />

Note : If the result shows like the ???? then u may need to install the external language support tool by enabling the following options,

Control Panel -> Regional and Language Option -> Languages -> Install files for complex script and right-to-left languages (including Thai).

Karthik Arwin
  • 405
  • 1
  • 4
  • 13
0

See "question marks" in Trouble with utf8 characters; what I see is not what I stored

If you still have trouble, provide

SHOW CREATE TABLE
Sample of the text being inserted
SELECT HEX(...) of a sample of the bad data (? = 3F)

Rick James
  • 135,179
  • 13
  • 127
  • 222