1

I am new to SQL and I don't to know how to save Farsi text (string) with emojis in database.

Do I have to change the collation of database? Right now, its utf8_persian_ci.

codesnerd
  • 767
  • 2
  • 8
  • 23
Meti
  • 25
  • 6
  • 1
    This may be a useful read https://stackoverflow.com/questions/6642755/insert-a-persian-text-in-mysql-table – RiggsFolly Mar 15 '21 at 10:20
  • 1
    And [this](https://stackoverflow.com/questions/27460469/storing-persian-arabic-text-in-mysql-database) and [this](https://stackoverflow.com/questions/20519496/persian-characters-issue-in-mysql-database) and [this](https://stackoverflow.com/questions/48595477/insert-in-mysql-database-when-post-from-c-sharp-code-in-persian-language) and [this](https://stackoverflow.com/questions/52344043/send-persian-string-to-mysql) – RiggsFolly Mar 15 '21 at 10:22
  • MySQL collations can be applied in a per-table or even per-column basis so you don't need to change the complete database encoding if you don't want to. – Álvaro González Mar 15 '21 at 12:03

2 Answers2

2

درود they way we do that is by using a utf8mb4_persian_ci

CREATE TABLE `users` (

) DEFAULT CHARSET = utf8mb4_persian_ci 

This is how we would go about doing that. Persian Text will be saved using utf8mb4 it also Supports Emoji's and Much Much more !

Ryan The Ghost
  • 116
  • 1
  • 13
0

UTF-8 characters may be any length from 1 to 4 bytes. MySQL made a goof, and their utf8 collation only allows 1 to 3 bytes. 4-byte characters (which include emoji) cannot be saved in MySQL's utf8 collation. Instead, you must use utf8mb4, which is a newer collation designed to fix the previous error.

So you want utf8mb4_persian_ci.

TRiG
  • 10,148
  • 7
  • 57
  • 107
  • those with Persian text – Meti Mar 15 '21 at 10:31
  • I see no reason that they should give you problems. `utf8mb4` allows *up to* 4 bytes per character. Single-byte characters, such as ASCII, will still work fine. – TRiG Mar 15 '21 at 10:32