views:

43

answers:

1

Hi,

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

As i am making my guestbook and so forth multilanguage i changed the collation to uft8_unicode_ci in mysql, everything works as it should, something that i did not think of was the type i use, my guestbook is multilanguage and for the name field a user cannot enter more than 50 characters, same for subject and 800 characters for guestbook message.

Now doing this check in php is straight forward ie. checking string length using the mb_ before strlen etc.

But i am concerned that data maybe truncuated in mysql. Obviously normal characters will be ok but when it's chineese characters and other weird characters obviously this is a concern for me as i don't know how varchar will calculate them.

Can someone elaborate please as i am not sure about this.

Thanks PHPLOVER

+1  A: 

Since mySQL 4.1, VARCHAR counts in characters instead of bytes.

You can safely specify a VARCHAR(255) type for a message field that needs to hold 255 characters.

Pekka
Thanks Pekka, that other person post was deleted? i tried to reply and it say it got deleted, as i was confused how they say i need a text field when on the link they provided it says varchar supports upto 65535 bytes. At the moment i got VARCHAR(800) , its very confusing thou as i thought if i wanted in my example 800 characters allowed in the varchar field then i would need to specify it like i have VARCHAR(800) .Thanks
PHPLOVER
@PHPLOVER VARCHAR used to support only 255 characters, but that changed ( I think) with 4.1. I'm not sure what your question is? A Varchar(800) should work fine for 800 characters.
Pekka
Hi Pekka, the reason why i am confused is you said "i can safely specify a VARCHAR(255)" which is only 255 characters and my guestbook message is 800 MAX so if i specify 255 the remaining 545 characters would be trunctuated i should imagine, and with it being multilanguage i wasn't sure how VARCHAR handeled for example chineese characters like 1 chineese character is equal to 1 byte , i found it confusing.Thanks
PHPLOVER
@PHPLOVER just specify a width you feel comfortable with - VARCHAR(800) is fine. Since mySQL 4.1, a varchar(800) can hold 800 chinese characters (which can be 2-4 bytes long)
Pekka
Thanks that answers my question Peeka :)
PHPLOVER
Thanks Pekka, now i think i understand. varchar(800) means it will accept 800 characters and each character can be upto 4 bytes long which for utf-8 is perfectly fine i beleive as utf-8 can have characters upto 4 bytes long if i am thinking rite. Thank you! for all your help :)
PHPLOVER
@PHPLOVER exactly, that should work. You're welcome.
Pekka