PHP + MySQL + Spanish -


my system deals spanish data. using laravel + mysql. database collation latin1 - default collation , tables structure looks this:

create table `product` (   `id` int(11) not null auto_increment,   `name` varchar(100) character set latin1 not null, ) engine=innodb auto_increment=298 default charset=utf8mb4; 

have few questions:

  1. i load data file db. practice utf8_encode($name) before inserting db? doing so, else comparison throw error : sqlstate[hy000]: general error: 1267 illegal mix of collations (latin1_swedish_ci,implicit) , (utf8_unicode_ci,coercible) operation '='

  2. if using utf8_encode way go, need utf8_encode name want search? i.e. select... name = utf8_encoded(name)?

  3. is there flaws or better way handle above? doing spanish first time (characters accents).

your product.name column has character set latin1. know that. has collation latin1_swedish_ci. that's default. original developers of mysql swedish. because you're working in spanish, want use latin1_spanish_ci collation; sorts Ñ after n. other latin-language collations sort them together.

because product.name column stored in latin1, bad, not good, idea use utf8_encode() on text before storing column.

your best course of action, if application new, make character set columns utf8mb4. means changing defined character set of name column. can convert text strings unicode before storing them.

you wise make default collation of each table utf8mb4_spanish_ci well. collations baked indexes varchar() columns. (if you're working in traditional spanish, in ch distinct letter, use utf8mb4_spanish2_ci.)


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -