简体   繁体   English

在QUERY中进行MYSQL整理

[英]MYSQL Collate in QUERY

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 . 表也​​是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: 在名为knihy(书籍)的表中我有字段Autor1 Autor2 Autor 3 Autor4 / Author 1 etc./这是我用于搜索的查询:

$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. 假设我已经在我的桌子上预订了Autor1 / Author1 /名称为“Šilíoá”,如果我正在寻找“Šilíoá”它也会被发现如果我正在寻找“Šilioa”,但如果我正在寻找“ silioa“没有找到任何东西。 So problem is in char "Š" and "š" how can I fix this problem? 问题是char“Š”和“š”我该如何解决这个问题? I found a lot tutorials on the internet but It still not work... 我在互联网上发现了很多教程,但它仍然不起作用......

You can fix it by setting table charset to utf8, collation to utf8_general_ci or utf8_unicode_ci. 您可以通过将表charset设置为utf8,将collat​​ion设置为utf8_general_ci或utf8_unicode_ci来修复它。 and you also need to set,in your code(connection string), charset to utf8. 你还需要在你的代码(连接字符串)中设置charset到utf8。

Example for connection string: 连接字符串示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM