同事下午遇到一问题,MySQL 和 Memcached 对于同一个key,不能对应起来。最终原因是:PHP将key写入MySQL数据库之前,没有经过trim()过滤首尾空格(关键是尾部空格),结果:
1、MySQL的varchar、char类型字段,SELECT .... WHERE 查询时忽略字段的尾部空格。例如varchar类型字段uidcode中,存储的含有尾部空格的内容“rewinx ”,通过以下三种方式均可查询到:
在MySQL手册第“11.4.1. CHAR和VARCHAR类型”节中写道(http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char):请注意所有MySQL校对规则属于PADSPACE类。这说明在MySQL中的所有CHAR和VARCHAR值比较时不需要考虑任何尾部空格。请注意所有MySQL版本均如此,并且它不受SQL服务器模式的影响。
2、PHP 的 Memcache 扩展,则在set、get时,自动将key中的空格,转换成了半角下划线“_”。当然,直接通过 Memcached 协议来读取,key值“rewinx ”就要写成“rewinx_”了。
示例:testmc.php
1、MySQL的varchar、char类型字段,SELECT .... WHERE 查询时忽略字段的尾部空格。例如varchar类型字段uidcode中,存储的含有尾部空格的内容“rewinx ”,通过以下三种方式均可查询到:
在MySQL手册第“11.4.1. CHAR和VARCHAR类型”节中写道(http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char):请注意所有MySQL校对规则属于PADSPACE类。这说明在MySQL中的所有CHAR和VARCHAR值比较时不需要考虑任何尾部空格。请注意所有MySQL版本均如此,并且它不受SQL服务器模式的影响。
2、PHP 的 Memcache 扩展,则在set、get时,自动将key中的空格,转换成了半角下划线“_”。当然,直接通过 Memcached 协议来读取,key值“rewinx ”就要写成“rewinx_”了。
示例:testmc.php
JoeKevin
2021-12-4 16:26
Games that have made many people give up because it has quite high skill requirements, are you one of them? Or will you conquer the game and make it tame before you? Experience and feel at The Impossible Game to confirm it!
paul
2022-11-15 17:45
As a leading e-commerce development company, we created Store24x7 that can help you in every way as soon as the orders start coming in. To enhance daily sales, we can help you regulate mobile, website, and phone orders. Ecommerce services
john
2022-11-15 20:20
we provide the guaranteed value with manageable projects to our valued clients. Web & Mobile App Development ServicesWeb & Mobile App Development Services
yojiyit888
2023-6-8 12:16
Thanks for sharing all these information, it’s so appreciated! dicks price match
Lucky cola
2024-2-7 15:04
Immerse yourself in the ultimate gaming universe. Lucky cola
hunain
2024-11-16 21:35
it is good as well as meanful. it is awesome weblog. Connecting is extremely helpful point. you've truly assisted many individuals that go to weblog and supply all of them usefull info. Bijoux Unika
seo
2024-11-19 19:52
Thanks with regard to publishing this type of excellent post! I discovered your site ideal for my personal requirements. It has fantastic as well as useful articles. Continue the great function! Iptv
huanin
2024-11-20 22:39
In fact dependable, fantastic, fact-filled advice in this case. A items Have let down, and that also clearly is valid in this case to boot. Most people consistently can make for a worthwhile read through. How can you show So i am floored?: )#) Cultivate the nice content pieces. iptv uk
分页: 3/3 1 2 3