-1

I have an issue where i am trying to write 'Hindi/Chinese' string to MySQL database. PHP is converting that to '????' and that is what i can see in mysql. To isolate issue when i directly put that string in mysql it writes it correctly. does anybody have any idea how i ca resolve this issue.

(my database and tables are in UTF8, PHP configuration set to UTF8)

for every connection to mysql i use set name and set character etc to UTF8

before interacting with mysql, send this two querys:

SET NAMES 'utf8';
CHARSET 'utf8';

When people dont know answer they will not accept the fact but start -ve voting or saying possible duplicate.. without understanding the problem.. which is not good..have great day...

Solution :- i was using below queries after connection.

SET NAMES 'utf8' 
SET CHARACTER SET 'utf8'

which was causing issue somehow i am not able to understand why?? but if i remove SET CHARACTER SET 'utf8' and only keep SET NAMES 'utf8' everything works fine.

Thank you everyone for your help, for those to who said it is possible duplicate and -ve voted.

SmartDev
  • 481
  • 3
  • 11
  • 30
  • See my answer to that post: http://stackoverflow.com/a/10924295/1291428 , be sure you save your php files as UTF8 NO BOM – Sebas Nov 07 '13 at 06:32
  • Set the collation of the fields in the database to utf8_unicode_ci – Jenz Nov 07 '13 at 06:32
  • Before there was SO people would actually go RTFM. To what end?? – mwhs Nov 07 '13 at 07:03
  • @Sebas i am not getting it how should i save php file (program in UTF8) is that something will cause the issue.. utf8_unicode_ci is already there in database. Deceze.. i have already read what you are trying to mention based on possible duplicate but my situation is after following all those suggestion. – SmartDev Nov 07 '13 at 07:09
  • When people dont know answer they will not accept the fact but start -ve voting or saying possible duplicate.. without understanding the problem.. which is not good..have great day... – SmartDev Nov 07 '13 at 07:16
  • There are simply 2 points at which an encoding conversion may happen: browser to PHP/PHP to browser and PHP to database/database to PHP. How these points can be correctly transitioned has been widely explained, for instance in the above duplicate or in [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/). If you followed all this and understood all this and are *still* in a situation where it doesn't work (which I hardly believe is possible if you did everything correctly), then you'll have to present a lot more proof and detail about what exactly is happening. – deceze Nov 07 '13 at 09:21
  • Thank you deceze.. i am able to find out what is issue.. edited question - added answer there. – SmartDev Nov 07 '13 at 10:46

2 Answers2

0

use following command in php to set encoding utf8 in first line of php

 <?php
   header('Content-Type: text/html; charset=utf-8');
   <?
alok.kumar
  • 380
  • 3
  • 11
0

Be sure your HTML document is in utf-8 too.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

This is important so that the browser of your client actually send utf-8 encoded characters.

Thibault
  • 1,566
  • 15
  • 22