0

I created a web service for Android in PHP to fetch data from database. The data is stored in Hindi but in database table it looks like

{ बारह भावना } 

format in database. After executing the API result is in

{ \u00e0\u00a4\u2022\u00e0\u00a5\u20ac } 

format.

Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87
  • Change field collation as `utf8_general_ci` where you store your text – Sadikhasan Aug 29 '17 at 12:26
  • collation is in utf8_general_ci format but still it showing same result – Arun Jadhav Aug 29 '17 at 12:31
  • First change utf8_general_ci then store your hindi text in that field after then you can check – Sadikhasan Aug 29 '17 at 12:34
  • facing same problem – Arun Jadhav Aug 29 '17 at 12:39
  • Check this link https://stackoverflow.com/q/12435867/2893413 may be useful to you. – Sadikhasan Aug 29 '17 at 12:41
  • 1
    I have previously written [**an answer about UTF-8 encoding**](https://stackoverflow.com/a/31899827/4535200) that contains a little checklist, that will cover *most* of the charset issues in a PHP/MySQL application. There's also a more in-depth topic, [UTF-8 All the Way Through](https://stackoverflow.com/q/279170/4535200). Most likely, you'll find a solution in either one or both of these topics. Note that any data already in the database, which has the wrong encoding, won't be magically fixed. That data needs to be updated - *after* the encoding issue has been fixed. – Qirel Aug 29 '17 at 12:43

1 Answers1

1

Follow this 2 step

(1) change database ,table and field collection to utf8mb4_bin

(2) use database connection character set utf8mb4_bin

e.g

For mysqli connection

$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
mysqli_set_charset($con,"utf8mb4_bin");

For pdo connection

$conn = new PDO("mysql:host=$host;dbname=$db;charset=utf8mb4_bin", $user, $pass);