How to insert Hindi language in Mysql
Asked Answered
A

7

9

I changed the charset as described here but does not work:

CREATE TABLE `tbl_hindi` (
  `data` varchar(1000) character set utf8 collate utf8_bin default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `tbl_hindi` VALUES ('कंप्यूटर');
Anselma answered 2/7, 2012 at 11:39 Comment(0)
P
28

The charset of the database needs to be utf8_unicode_ci.

Try creating a new database, as well as a new table.

CREATE DATABASE hindi_test
    CHARACTER SET utf8
    COLLATE utf8_unicode_ci;

USE hindi_test;

CREATE TABLE `hindi` (
    `data` varchar(200) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `hindi` (`data`) VALUES
    ('कंप्यूटर');

This works on my install. If it doesn't work for you, something might be wrong with your server settings.

Pregnant answered 2/7, 2012 at 12:8 Comment(3)
It doesnt work for me! I got ?????, Its showing there in phpmyadmin but not after I get it through API call. What to do with server setting??Circularize
@PalakDarji Sounds like an encoding problem in your browser.Kef
@PalakDarji how did you solve that? Please help me out if this worked for you.Halloween
R
10

You do not need database change, all you need is to alter table column.

ALTER TABLE `YOUR TABLE` CHANGE `data ` `data ` VARCHAR(1000) 
CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL; 

This change works fine and very feasible.

Reinstate answered 29/12, 2015 at 15:48 Comment(0)
N
3

If the table has already been created and the problem is about storing (your) local language characters, utf8_general_ci or utf16_general_ci would be for you: Fire following query:

ALTER TABLE 'tbl_hindi' CHANGE 'data' 'data' VARCHAR(1000) CHARSET utf8 COLLATE utf16_general_ci DEFAULT '' NOT NULL;

or

ALTER TABLE 'tbl_hindi' CHANGE 'data' 'data' VARCHAR(1000) CHARSET utf8 COLLATE utf8_general_ci DEFAULT '' NOT NULL;

If this too doesn't solve your problem, try altering the database collation to utf16_general_ci.

Noblewoman answered 15/2, 2016 at 13:36 Comment(3)
I got the error after alter the table above command COLLATION 'utf16_general_ci' is not valid for CHARACTER SET 'utf8' Then i ran the below one that's work for me ALTER TABLE tb_contest_details CHANGE termsCondition termsCondition VARCHAR(1200) CHARSET utf8 COLLATE utf8_general_ci DEFAULT '' NOT NULL;Ferrin
@RaviTyagi i had already stated in preface about "utf8_general_ci" or "utf16_general_ci"Noblewoman
Yes after some R&D it works for me.Ferrin
F
0

Below one work for me

ALTER TABLE TableName CHANGE OldColumnName NewColumnName VARCHAR(1200) CHARSET utf8 COLLATE utf8_general_ci DEFAULT '' NOT;

Ferrin answered 2/7, 2012 at 11:39 Comment(0)
H
0

from your phpmyadmin change collation of your table to utf16_general_ci... Note: it worked for me..

Horseradish answered 15/10, 2017 at 17:25 Comment(0)
K
0

Try this:

CREATE TABLE tbl_hindi (
    data nvarchar(1000),
);
INSERT INTO tbl_hindi VALUES (N'कंप्यूटर');
SELECT * FROM tbl_hindi;
Kneecap answered 29/1, 2018 at 5:23 Comment(0)
M
-2

just use N before the value like this $sql="insert into indextbl Values('Null',N'$abc')";

Matthew answered 27/8, 2015 at 12:30 Comment(1)
I'm sorry, but how is this supposed to help? Also, why does your answer contain what looks like PHP?Kef

© 2022 - 2024 — McMap. All rights reserved.