What happens if there are spaces behind MySQL and memcache field names

Source: Internet
Author: User
Tags memcached mysql manual vars

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?
    1. <?php
    2. $memcache _obj = new Memcache;
    3. $memcache _obj->connect (' 192.168.8.34 ', 11211);
    4. $memcache _obj->set (' Rewinx ', ' Hello World ');
    5. echo $memcache _obj->get (' Rewinx ')."  \ r \ n ";
    6. ?>

  

from:http://zyan.cc/mysql_memcached_space/

What happens when MySQL and memcache field names have spaces behind them (go)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.