drd0833 2012-10-17 10:30 采纳率: 100%
浏览 6
已采纳

从数据库中逃避特殊字符 - MySql

Hi guys I need to search for a data in the database like 123.456.789 how can I search it even if I only entered 123456789 ? I need to escape the special characters from the database so that even if i search for 123456789 it can also display values like 123.456.789.

Here is my query:

SELECT *
FROM clients 
WHERE REPLACE(phone, '.', '') LIKE ".$searchtext."

... where searchtext is the number im looking for. It should return all values that match regardless of whatever special characters are present.

  • 写回答

4条回答 默认 最新

  • doufu9145 2012-10-17 11:28
    关注

    @Kiel

    Here is the sample table & query. Please see if this can help you. Not sure about your table structure.

     CREATE TABLE `clients` (
     `id` int(11) NOT NULL,
     `phone` varchar(255) NOT NULL
     ) ENGINE=InnoDB;
    
    INSERT INTO `test`.`clients` (
    `id` ,
    `phone`
    )
    VALUES (
     '1', '123.456.789'
    ), (
    '2', '123.456.785'
    );
    
    
    
    mysql> select * from clients where replace(phone,'.','') = '123456789'; 
    +----+-------------+
    | id | phone       |
    +----+-------------+
    |  1 | 123.456.789 |
    +----+-------------+
    

    Hope this help !

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?