Redian新闻
>
how to query chinese in mysql?
avatar
how to query chinese in mysql?# Database - 数据库
a*p
1
seems that mysql will add unicode support in the near future.
when I query like "%猪%"
it will return lots of unrelated items, which might contain the two bytes
of 猪 but not belonging to the same chinese character.
true?
avatar
a*p
2
没人回答我,赫赫,我自己想了个笨办法:
因为我用的PHP也不支持unicode,我就:
数据库出来的数据再用unicode_like_compare做过滤,应该可以在很大程度上解决问题。
这个应该还是暂时方案吧,等mysql的unicode support吧。
function to_unicode_like($str) {
$r = "";
for ($i=0;$i$ch = substr($str,$i,1);
if (ord($ch) < 127) $r .= " $ch";
else {
if ($i == strlen($str)-1) $r .= $ch;
else {
$r .= substr($str,$i,2);


【在 a*p 的大作中提到】
: seems that mysql will add unicode support in the near future.
: when I query like "%猪%"
: it will return lots of unrelated items, which might contain the two bytes
: of 猪 but not belonging to the same chinese character.
: true?

avatar
b*e
3
oracle supports unicode directly.. for databases
that do not support unicode i would always base64encode
the string before storing it into the db.. to do a compare
base64encode the "pig" first too of course

【在 a*p 的大作中提到】
: 没人回答我,赫赫,我自己想了个笨办法:
: 因为我用的PHP也不支持unicode,我就:
: 数据库出来的数据再用unicode_like_compare做过滤,应该可以在很大程度上解决问题。
: 这个应该还是暂时方案吧,等mysql的unicode support吧。
: function to_unicode_like($str) {
: $r = "";
: for ($i=0;$i: $ch = substr($str,$i,1);
: if (ord($ch) < 127) $r .= " $ch";
: else {

avatar
a*p
4
I thought this solution before.:-)
but how to deal with where blah like '%pig%'? that's what I need.

【在 b****e 的大作中提到】
: oracle supports unicode directly.. for databases
: that do not support unicode i would always base64encode
: the string before storing it into the db.. to do a compare
: base64encode the "pig" first too of course

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。