Home  >  Article  >  Backend Development  >  请问一下thinkphp 查询条件 单引号转义的问题

请问一下thinkphp 查询条件 单引号转义的问题

WBOY
WBOYOriginal
2016-06-23 13:48:511734browse

$model=M('Book');
$map['lb_author']=array('like',"%mike's%");
$model->where($map)->field('lb_id')->limit(10)->select();
打印sql:
正确的结果应该是
SELECT `lb_id` FROM `lb_book` WHERE ( `lb_author` LIKE '%mike's%' ) LIMIT 10 
但是
SELECT `lb_id` FROM `lb_book` WHERE ( `lb_author` LIKE '%mike\'s%' ) LIMIT 10  // thinkphp自动对‘进行了转义,这样的话,数据库里什么也查不到

请问如何避免转义?


回复讨论(解决方案)

不知道你为何要再定义的时候加上特殊字符,如果可以的话可以考虑在写入的时候先进行转义,这样到数据SQL组装的时候就不会出现重新转义的问题。

单引号中的单引号必须转义
所以你说的情况不出在

Statement:
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