Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Please help me to find out why arabic text is not storing in the databse. It changes to some other unicode format such as %$&^%$%^&!#* ..

I'vbe made my column Collation as utf8_general_ci . Please tell me if i've to do some modification in my sql query. I am in urgent need. tons of Thanks in advance. My sql query is $query="INSERT INTO blog_tab(blog_details) VALUES('$blog_details') ";

share|improve this question
1  
change your collation to utf8_unicode_ci –  user1432124 Jun 6 '12 at 12:12
    
are you using UTF8 character set? –  BrokenGlass Jun 6 '12 at 12:13
    
thanks for the quick response. Yes I am using UTF8 in database as Collation. –  Shashi Roy Jun 6 '12 at 12:14
    
@Somebodyisintrouble : Thanks for the response. But its not working. :( –  Shashi Roy Jun 6 '12 at 12:15
add comment

2 Answers

The character set, collation and encoding seem to be correct.

Adding the following before connecting to the DB is supposed to help:

mysql_query("SET NAMES 'utf8'"); 
mysql_query('SET CHARACTER SET utf8');

The page at http://www.adviesenzo.nl/examples/php_mysql_charset_fix/ contains an explanation and further guidance for your issue.

share|improve this answer
    
I'll try it. Please be there. ll be back with my reponse. Thanks a lot for the quick response. –  Shashi Roy Jun 6 '12 at 12:16
    
$link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8'); mysql_select_db('future'); $blog_details =$_POST['elm1']; $query="INSERT INTO blog_tab(blog_details) VALUES('$blog_details') "; $result=mysql_query($query); echo "success"; I am trying something like this but its not working. :( Please help me –  Shashi Roy Jun 6 '12 at 12:18
    
What version of MySQL are you using? Have you set accept-charset="utf-8" ? Did you read the link I posted? –  smartcaveman Jun 6 '12 at 13:26
add comment

When you create the database, the SQL might be like this:

CREATE TABLE IF NOT EXISTS `employees` (
  `empid` int(11) NOT NULL,
  `empname` varchar(255) NOT NULL,
  PRIMARY KEY (`empid`)
) ENGINE=InnoDB ;

or like this:

CREATE TABLE IF NOT EXISTS `employees` (
  `empid` int(11) NOT NULL,
  `empname` varchar(255) NOT NULL,
  PRIMARY KEY (`empid`)
) ENGINE=InnoDB charset=latin1 ;

Try changing the charset to utf-8 as shown below:

CREATE TABLE IF NOT EXISTS `employees` (
  `empid` int(11) NOT NULL,
  `empname` varchar(255) NOT NULL,
  PRIMARY KEY (`empid`)
) ENGINE=InnoDB charset=utf-8 ;

Hope this helps! :)

share|improve this answer
    
Hi thanks for the response. Still it is not working. I changed the charset to utf-8 too. :( –  Shashi Roy Jun 6 '12 at 12:25
    
If you use phpMyAdmin, try changing the collation with that... And after changing it, you need to again re-insert the data to be stored in utf-8, as the old data would have converted to latin1 charset. Got it? Re-insert the data again and check if it is working. :) –  Praveen Kumar Jun 6 '12 at 13:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.