select * from product where model like '%$key%'
这个可以搜索中文
select * from product where binary model like '%$key%'
这个不可以搜索中文
望大师们帮一下解决一下!折腾好久了!
php文件 数据库 表 全都是utf8编码
如果是编码问题,第一个应该就不能搜索才对呀!
这个可以搜索中文
select * from product where binary model like '%$key%'
这个不可以搜索中文
望大师们帮一下解决一下!折腾好久了!
php文件 数据库 表 全都是utf8编码
如果是编码问题,第一个应该就不能搜索才对呀!
2. show variables like 'char%';
贴结果,估计是字符集问题
product CREATE TABLE `product` ( `pid` smallint(5) unsigned NOT NULL
`pmodel` varchar(20) CHARACTER SET utf8 NOT NULL
`bigclass` smallint(2) unsigned NOT NULL
`smallclass` smallint(2) unsigned NOT NULL
`pindex` text COLLATE utf8_unicode_ci NOT NULL
`pdescription` text COLLATE utf8_unicode_ci NOT NULL
`pimage` char(18) COLLATE utf8_unicode_ci NOT NULL
PRIMARY KEY (`pid`)
KEY `bigclass` (`bigclass`)
KEY `smallclass` (`smallclass`)
CONSTRAINT `product_ibfk_1` FOREIGN KEY (`bigclass`) REFERENCES `class` (`cid`)
CONSTRAINT `product_ibfk_2` FOREIGN KEY (`smallclass`) REFERENCES `class` (`cid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
找全文搜索解决您的问题吧。
现在我用mysql command line输入show variables like 'char%'时显示的是utf8,
但我用php用以上命令做查询时,出现的是以下结果:
character_set_client latin1
character_set_connection latin1
character_set_database utf8
character_set_filesystem binary
character_set_results latin1
character_set_server utf8
character_set_system utf8
character_sets_dir D:\web\mysql\share\charsets\
collation_connection latin1_swedish_ci
collation_database utf8_general_ci
collation_server utf8_general_ci
completion_type 0
concurrent_insert 1
connect_timeout 10
控制台和php查询的结果怎么会不一样呢
看看这个
sql语句可以用:
select * from product where model like '%a%'
前提条件,表一定要是utf8编码,至于用哪种utf-8都可以!
刚才9楼的兄弟提供的网址我看了,看来不是我一个人遇到这样的问题,只不过他用utf8_general_ci而不用utf8_general_ci就可以解决问题,而我现在用utf8_general_ci也不行!
id int primary key,
f1 varchar(10)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci ;insert into tx values (1,'工工');
insert into tx values (2,'aa');
insert into tx values (3,'问题还');select * from tx;select * from tx where f1 like '%a%';建议你检查一下你数据库中存放的到底是什么。
mysql> select hex(f1) from tx;
+--------------------+
| hex(f1) |
+--------------------+
| E5B7A5E5B7A5 |
| 6161 |
| E997AEE9A298E8BF98 |
+--------------------+
3 rows in set (0.00 sec)工的UTF码是 E5B7A5
mysql_query("set name 'utf8'");
mysql_query("insert into tx values (10,'数据')")
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
C3 A5 C2 B7 C2 A5
这个是什么码,为什么读取后用bin2hex($outval)显示的是utf8正常编码E5 B7 A5;
ACMAIN_CHM高手,另外两个贴已结贴并送上85分,希望笑纳,这个贴还有一点点疑问,希望能解答一下,然后再将分数一起奉上!~
用SET NAMES UTF8后,
再插入记录试试
Incorrect string value: '\xE5\xB7\xA5\xE7\xA8\x8B...'
我在mysql command line client中直接insert into时就会出现上面类似的错误!
但我在php中没有看到任何报错,我上面提到的数据中‘工’的编码到底是什么编码?