prohor Posted September 11, 2016 Share Posted September 11, 2016 I want to retrieve unicode based (Bengali language) data from mysql (wamp server 3 is running). I have inserted data using PhpMyAdmin and can read the font. but when I tried to read using php in html it just shows '?????' ! I know it is creating problem with unicode data. any solution?? how I can handle in PHP when I can read data from PhpMyAdmin ? my code is: for lastest row only PHP Code: <?php $connect = mysqli_connect("localhost", "root", "", "sumonn"); $sql=("SELECT * FROM `notice` ORDER BY id DESC limit 1" ); $result_set=mysqli_query($connect,$sql); while($row=mysqli_fetch_array($result_set)) { echo $row['notice']; } ?> Please help! Quote Link to comment https://forums.phpfreaks.com/topic/302150-unicode-data-retrieve-from-mysql-using-php-problem/ Share on other sites More sharing options...
Solution Jacques1 Posted September 11, 2016 Solution Share Posted September 11, 2016 mysqli::set_charset() Also make sure that your HTML documents are declared as UTF-8 (with a Content-Type: text/html;charset=UTF-8 HTTP header and a <meta charset="UTF-8"> element). Quote Link to comment https://forums.phpfreaks.com/topic/302150-unicode-data-retrieve-from-mysql-using-php-problem/#findComment-1537372 Share on other sites More sharing options...
prohor Posted September 11, 2016 Author Share Posted September 11, 2016 @ Jacques1 << thank you very much. it solved my problem! <meta charset="utf-8"> was there but your "mysqli::set_charset()" link solved my problem. I added my code and looks like bellow <?php $connect = mysqli_connect("localhost", "root", "", "sumonn"); // this lines solved my problme, changing latin1 to utf8 after connction (start) if (!mysqli_set_charset($connect, "utf8")) { printf("Error loading character set utf8: %s\n", mysqli_error($connect)); exit(); } else { printf("Current character set: %s\n", mysqli_character_set_name($connect)); } // this was the last line of my changed code $sql=("SELECT * FROM `notice` ORDER BY id DESC limit 1" ); $result_set=mysqli_query($connect,$sql); while($row=mysqli_fetch_array($result_set)) { echo $row['notice']; } if (!mysqli_set_charset($connect, "utf8")) { printf("Error loading character set utf8: %s\n", mysqli_error($connect)); exit(); } else { printf("Current character set: %s\n", mysqli_character_set_name($connect)); } ?> Hope it will help others like mine. Quote Link to comment https://forums.phpfreaks.com/topic/302150-unicode-data-retrieve-from-mysql-using-php-problem/#findComment-1537374 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.