同事下午遇到一问题,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
SDFSFSD
2024-11-25 14:50
The Debox Method provides a structured approach for individuals to process and heal from their trauma, as outlined in our digital book available at https://debox.Co/debox-digital-book/. It offers practical exercises that focus on acknowledging trauma's impact on the body and mind, promoting a pathway towards recovery. Through personal narratives included in the book, readers gain insights into how others have successfully navigated their healing journey using the Debox Method. The digital book also introduces a unique framework for understanding trauma's effects, which is essential for devising a personalized healing strategy. It emphasizes the importance of creating a safe environment for oneself, both physically and emotionally, to facilitate the healing process. The method highlights the role of supportive relationships in overcoming trauma, providing strategies to strengthen connections with others. Readers learn to identify triggers and develop coping mechanisms that can be employed in moments of distress. The book offers guidance on how to gradually reintegrate traumatic memories, reducing their power over the individual's life. It encourages a holistic view of healing, integrating physical activities such as yoga or meditation to support mental health. The Debox Method stresses the significance of patience and self-compassion on the journey to recovery, recognizing that healing from deep trauma is a gradual process. overcome deep trauma Debox Method
分页: 3/3 1 2 3