0

MySQL throws an error on INSERT QUERY when two different strings jardiniere and jardinière are inserted in a column (named word) having UNIQUE KEY enabled.

Error: #1062 - Duplicate entry 'jardinière' for key 'word'

I've also included following line before INSERT Query (in PHP File)

mysqli_set_charset($con, "utf8");

How can I resolve this error?

ShivCK
  • 557
  • 10
  • 16

1 Answers1

2

The collation of the table (the specific column) needs to be set to utf8_bin in order to separate the two characters from one another.

Run the following query to update the charset and the collation (you can set it to utf8_bin if you need it on just that column).

ALTER TABLE myTable
CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;

Keep in mind that unlike latin_* and utf8_XXX_ci, the utf8_bin is case sensitive when comparing.

Qirel
  • 25,449
  • 7
  • 45
  • 62