Colleague in the afternoon encountered a problem, MySQL and Memcached for the same key, can not be matched up. The final reason is: before PHP writes key to the MySQL database, it does not pass trim () to filter the first and last spaces (the key is trailing spaces), the result:
1. The MySQL varchar, char type field, SELECT .... The WHERE query ignores trailing spaces for the field. For example, in the varchar Type field Uidcode, the content "Rewinx" stored with trailing spaces can be queried in the following three ways:
In the MySQL manual section "11.4.1. char and varchar type "section writes (Http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char): Note that all MySQL proofing rules belong to the Padspace class. This means that there is no trailing space to consider when comparing all char and varchar values in MySQL. Note that all MySQL versions are the same, and that it is not affected by SQL Server mode.
2, PHP Memcache extension, when set, get, automatically the key in the space, converted into a half-width underscore "_". Of course, directly through the Memcached protocol to read, the key value "Rewinx" will be written "Rewinx_".
Example: testmc.php
View Plainprint?
- <?php
- $memcache _obj = new Memcache;
- $memcache _obj->connect (' 192.168.8.34 ', 11211);
- $memcache _obj->set (' Rewinx ', ' Hello World ');
- echo $memcache _obj->get (' Rewinx ')." \ r \ n ";
- ?>
from:http://zyan.cc/mysql_memcached_space/
What happens when MySQL and memcache field names have spaces behind them (go)