Question

Hi I am trying to make search on my web which is looking in DB with

CHARACTER SET utf8 COLLATE utf8_slovak_ci

Table is also utf8_slovak_ci . In table called knihy (books) I have fields Autor1 Autor2 Autor 3 Autor4 /Author 1 etc./ Here is query which I am using for searching:

$q = $this->db->query("SELECT * FROM (`knihy`) 
              WHERE `stav` = 1 
              AND (Autor1 LIKE '$vyraz' 
              OR Autor2 LIKE '$vyraz' 
              OR Autor3 LIKE '$vyraz' 
              OR Autor4 LIKE '$vyraz') 
              ORDER BY `id` desc LIMIT $limit OFFSET $offset ");

Lets say I have Book in my table with Autor1 /Author1/ with name "Šilíoá" if I am looking for "Šilíoá" It will be found also It will be found if I am looking for "Šilioa" but if I am looking for "silioa" nothing will be found. So problem is in char "Š" and "š" how can I fix this problem? I found a lot tutorials on the internet but It still not work...

Was it helpful?

Solution

You can fix it by setting table charset to utf8, collation to utf8_general_ci or utf8_unicode_ci. and you also need to set,in your code(connection string), charset to utf8.

Example for connection string:

string cs = @"server=localhost(or IP address);userid=root;password=xxx;database=table_name;charset=utf8";

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top