Seperti yang ditunjukkan oleh @Tim Anda perlu mengubah collation
tabel/database/kolom Anda ke UTF-8
. Pertama, periksa susunan database/table/column
Anda .
PERIKSA PENGUMPULAN:
Cara memeriksa susunan DATABASE:
SELECT
default_character_set_name
FROM
information_schema.SCHEMATA
WHERE
schema_name = "YOUR_DATABASE_NAME";
Cara memeriksa susunan TABEL:
SELECT
CCSA.character_set_name
FROM
information_schema.`TABLES` T,
information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE
CCSA.collation_name = T.table_collation
AND T.table_schema = "YOUR_DATABASE_NAME"
AND T.table_name = "YOUR_TABLE_NAME";
Cara memeriksa susunan KOLOM:
SELECT
character_set_name
FROM
information_schema.`COLUMNS`
WHERE
table_schema = "YOUR_DATABASE_NAME"
AND table_name = "YOUR_TABLE_NAME"
AND column_name = "YOUR_COLUMN_NAME";
Ubah KOLASI:
Cara mengubah susunan basis data:
ALTER DATABASE YOUR_DATABASE_NAME CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Cara mengubah susunan tabel:
ALTER TABLE YOUR_TABLE_NAME CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Cara mengubah susunan kolom:
ALTER TABLE YOUR_TABLE_NAME MODIFY YOUR_COLUMN_NAME VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Contoh:
DROP TABLE IF EXISTS `sample_table`;
CREATE TABLE `sample_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`language` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO sample_table(name,language) VALUES('Ed Sheeran','English');
INSERT INTO sample_table(name,language) VALUES('আয়েশা খাতুন সুজানা','আমার সোনার বাংলা');
Lihat, CHARSET
digunakan dalam definisi tabel adalah utf8
. Jadi, Anda dapat menyimpan unicode characters
dalam tabel.
Periksa apakah data yang dimasukkan benar atau tidak.
SELECT * FROM sample_table
;
Hasil:
| id | name | language |
|----|--------------------|------------------|
| 1 | Ed Sheeran | English |
| 2 | আয়েশা খাতুন সুজানা | আমার সোনার বাংলা |