ThinkPHP中高效运用LIKE关键字进行模糊查询
在做项目的过程中,需要用到like关键字来组合查询条件,下面作者将在thinkphp中使用到的 like 查询做一下分享。
这里主要通过举例来说明用法:
-
- $where['name']=array('like','phpernote%');
- $userForm->where($where)->select();
复制代码
这里的like查询即为:name like 'phpernote%'
-
- $where['name']=array('like',array('%phpernote%','%.com'),'OR');
复制代码
这里的like查询即为:name like '%phpernote%' or name like '%.com'
-
- $where['name']=array(array('like','%a%'),array('like','%b%'),array('like','%c%'),'phpernote','or');
复制代码
这里的like查询即为:(`name` LIKE '%a%') OR (`name` LIKE '%b%') OR (`name` LIKE '%c%') OR (`name` = 'phpernote')
-
- $where['_string']='(name like "%phpernote%") OR (title like "%phpernote")';
复制代码
这里的like查询即为:name like '%phpernote%' or title like '%phpernote'
|