Varchar for UTF-8?

I found a similar post about this, but still not sure.

How do I do my guest book, etc. multilingual, I changed the mapping from uft8_unicode_ci in mysql, everything works as it should, what I did not think about the type I use, my guest book is multilingual and for the name field the user can not enter more than 50 characters, the same for a topic and 800 characters for a guestbook message.

Now performing this check in PHP is straightforward, i.e. checking string length with mb_before strlen etc.

But I am concerned that the data may be truncated in mysql. Obviously, normal characters will be fine, but when Chinese characters and other non-standard characters, it obviously bothers me, since I don't know how varchar will calculate them.

+3
source share
1 answer

Since mySQL 4.1, VARCHAR is counted in characters instead of bytes.

You can safely specify the type VARCHAR(255)for the message field, which must be 255 characters long.

+4
source

Source: https://habr.com/ru/post/1763228/


All Articles