在Zen Cart 后台搜索订单,当搜索词为中文或日文时,出现如下错误信息:
MySQL版本为 V5.5.30, 同样的情况在MySQL V5.1.6 没有问题。
Zen Cart 版本为 V1.3.9h
1271 Illegal mix of collations for operation ‘like’
in:
select count(*) as total from (orders_status s, orders o ) left join orders_total ot on (o.orders_id = ot.orders_id) where (o.orders_status = s.orders_status_id and s.language_id = '2' and ot.class = 'ot_total') and (o.customers_city like '%才哥%' or o.customers_postcode like '%才哥%' or o.date_purchased like '%才哥%' or o.billing_name like '%才哥%' or o.billing_company like '%才哥%' or o.billing_street_address like '%才哥%' or o.delivery_city like '%才哥%' or o.delivery_postcode like '%才哥%' or o.delivery_name like '%才哥%' or o.delivery_company like '%才哥%' or o.delivery_street_address like '%才哥%' or o.billing_city like '%才哥%' or o.billing_postcode like '%才哥%' or o.customers_email_address like '%才哥%' or o.customers_name like '%才哥%' or o.customers_company like '%才哥%' or o.customers_street_address like '%才哥%' or o.customers_telephone like '%才哥%' or o.ip_address like '%才哥%')
If you were entering information, press the BACK button in your browser and re-check the information you had entered to be sure you left no blank fields.
解决方案:
编辑后台的两个文件 your_admin_folder/orders.php, your_admin_folder/tracker.php (如果你装了Ty Package Tracker 这个插件,才有tracker.php这个文件)。
搜索并将
1
or o.date_purchased like '%"
改为
1
or o.date_purchased like binary '%"
问题解决。
从SQL语句方面分析这个问题,发现是 o.date_purchased like ‘%才哥%’ 导致整个SQL语句执行报错
错误原理分析以及错误解决方法:
在 MySQL 5.5 以上, 若字段 Type 是 time, date, datetime
在 select 時若使用 like ‘%中文%’ 会出現 Illegal mix of collations for operation ‘like’
在写程序时要对每个字段进行搜索,在执行时可能就会出现时间字段 like ‘%才哥%’ 这种语法,这在像MySQL V4.0,5.1这种比较老的版本MySQL是不会出现错误的。
但是升级到MySQL 5.5以上,必需改成like binary ‘%才哥%’ 即可避免出现错误
(责任编辑:好模板) |