Home > Database > Mysql Tutorial > MySql LIKE查找带反斜线“”的记录

MySql LIKE查找带反斜线“”的记录

WBOY
Release: 2016-06-07 17:53:10
Original
1371 people have browsed it

在mysql中like模糊查询是不支持反斜线查询了,因为普通情况下在mysql中反斜线是转议的哦,下面我来给大家介绍如何利用MySql LIKE查找带反斜线的记录,有需要的朋友可进入参考。

使用 还是 \ 看你如何的定义字符串的。其实只有两处转义:PHP 中 和 MySQL 中。

PHP 中 如果你用双引号”" 定义字符串, 那么这里有一次转义。如果用单引号就不会转义。

$sql = “SELECT * FROM table WHERE col LIKE ‘%a\\%’ “;

这样实际上经过转义发给 MySQL 的是

SELECT * FROM table WHERE col LIKE ‘%a\%’;

用单引号则不会转义(除了单引号,当然变量也不会展开):

$sql = ‘SELECT * FROM table WHERE col LIKE ’%a\%’ ‘;

发给 MySQL 的也是

SELECT * FROM table WHERE col LIKE ‘%a\%’;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template