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 ('कंप्यूटर');
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Sanjay Dutt
  • 165
  • 2
  • 2
  • 8

7 Answers7

27

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.

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
9

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.

anwerj
  • 2,386
  • 2
  • 17
  • 36
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.

sifr_dot_in
  • 3,153
  • 2
  • 33
  • 42
  • 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; – Ravi Tyagi Feb 08 '23 at 18:15
  • @RaviTyagi i had already stated in preface about "utf8_general_ci" or "utf16_general_ci" – sifr_dot_in Feb 09 '23 at 04:08
  • Yes after some R&D it works for me. – Ravi Tyagi Mar 24 '23 at 09:02
0

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

danish-khan-I
  • 776
  • 6
  • 15
0

Try this:

CREATE TABLE tbl_hindi (
    data nvarchar(1000),
);
INSERT INTO tbl_hindi VALUES (N'कंप्यूटर');
SELECT * FROM tbl_hindi;
Omar Einea
  • 2,478
  • 7
  • 23
  • 35
0

Below one work for me

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

Ravi Tyagi
  • 157
  • 2
  • 5
-2

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