solaro
V2EX  ›  问与答

mysql 下数据是存在的,但是无法 select 出数据

  •  
  •   solaro · Jan 22, 2018 · 2176 views
    This topic created in 3214 days ago, the information mentioned may be changed or developed.

    问题如下:

    短信发送记录表:sms

    CREATE TABLE `sms` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `uid` int(11) NOT NULL DEFAULT '0' COMMENT '接收人',
      `phone` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '接收手机',
      `code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '验证码',
      `content` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '短信内容',
      `overdue` int(11) NOT NULL DEFAULT '0' COMMENT '过期时间',
      `error` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '发送失败的错误信息',
      `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '发送状态:0-发送失败、1-发送成功',
      `is_overdue` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否已过期:0-未过期、1-已过期',
      `is_used` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否已使用:0-未使用、1-已使用',
      `created_at` datetime DEFAULT NULL COMMENT '创建时间',
      `updated_at` datetime DEFAULT NULL COMMENT '最后更新时间',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='短信发送日志表';
    

    问题

    执行如下正常,可以查出记录
    select * from sms where uid = 0 
    
    执行如下,特么的会丢失记录
    select * from sms where uid = 0 and phone = '17750XXXX44' 
    

    求解,上面的问题好蛋疼,是不是因为 urlencode 问题?用的是某片的短信发送接口,所有手机号都要 urlencode 一遍再发送短信并存储到数据库里作记录
    
    8 replies  •  2018-01-23 09:50:24 +08:00
    msg7086
    msg7086
    Jan 22, 2018
    1
    无责任猜测:and phone like 'xxx'
    mengyaoss77
    mengyaoss77
    Jan 22, 2018
    2
    存到数据库的部分就别 urlencode 了呗
    glues
    glues
    Jan 22, 2018
    3
    有没有可能是 phone 数据前后有空格?
    InternetExplorer
    InternetExplorer
    Jan 22, 2018
    4
    手机号 urlencode 不还是手机号?数字 urlencode 前后有区别吗
    >>> urlencode('1234567890')
    => "1234567890"
    SeanChense
    SeanChense
    Jan 22, 2018
    5
    有没有可能是 phone 数据前后有空格?
    以及不可见字符
    CosimoZi
    CosimoZi
    Jan 22, 2018
    6
    90%是控制字符的锅
    fatttt
    fatttt
    Jan 23, 2018 via Android
    7
    我猜手机号有问题
    solaro
    solaro
    OP
    Jan 23, 2018
    8
    谢谢各位,是字符编码的问题。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1137 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 98ms · UTC 18:03 · PVG 02:03 · LAX 10:03 · JFK 13:03
    ♥ Do have faith in what you're doing.