I am android developer and using PHP just for getting data from MySQL (so my PHP is very poor) and it always works but I come across that I can't get data with non-english letters
I have written that kind of question How to put in JSON Object non-english letters?
but in that question I thought that problem was in json encoding, but it was not problem in json.(but now I know how to solve problem with json) so I need just to get non-english text data from MySQL
I thought that problem was in database so I changed everything to utf-8
, checked twice, made the same query in database and get expected result, so problem is in php code.
then I researched and thought that maybe my php didn't maintain utf-8, and that line <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
to the top then create a simple String variable that consist non English letters and echo that variable, and it has showed me what I expect, so I think php support utf-8
so I think the only problem is in the part with mysqli_query
that is my code :
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<?php
header("Content-type: text/html; charset=utf-8");
$con = mysqli_connect(...);
$sql = "SELECT * FROM news WHERE status = 'actual' ORDER BY id DESC";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - TITLE: " . $row["title"]. " -TEXT: " . $row["text"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($con);
?>
it is my data base datas:
and structure:
for all database
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation: utf8_unicode_520_ci
I expected to get the same datas as in title and text columns (you can see datas above)
but I get:
id: 4 - TITLE: ???????? -TEXT: ????????? ??????? ?????, ? ??? ????????? ?? ?????????
id: 3 - TITLE: A little bit... -TEXT: Just some more patience! And you will get this wonderfull application!
id: 1 - TITLE: �p�???�? -TEXT: Just wait a little bit!
I tried to write with all details of my problem, so help me with code, what I should add/modify (in which line?) to get expected result. Thank you all in advance!
SOLUTION HAS BEEN FOUND
I should add
$con->set_charset("utf8");
before declaring $sql