TP5中find_in_set的用法

TP5.1.22版本

$id=4;
Db::name('menu')->where('FIND_IN_SET(:id,pid_all)',['id' => $id])->update([$field => $title]);

 

$map[]=['exp','FIND_IN_SET(2,needID)'];php

$db->where($map)->select();數組

 

TP5.1.21   版本以後數組查詢支持:

要達到這樣子查詢:code

一、首先引用: use think\db\Where;ci

二、定義數組:$where = new Where;字符串

三、就能夠用了:$where['title'] = ['like', "%".$sotitle."%"];it

$where['class_id'] = ['in', '$cid_all'];
$where['id'] = ['in', $all_user_id];//或這樣子
$where['title'] = ['like', '%php%'];
$where['id'] = ['<>', $id];
$where['id'] = ['notin', $all_user_id];//不等於
 
 
//值爲數字
$id=419;
$where[] = ['exp',Db::raw("FIND_IN_SET($id,category)")];//category值爲數字,例子:419,415,414
//值爲字符串
$id值等於dfd 要注意'引號
$where[] = ['exp',Db::raw("FIND_IN_SET('$id',category)")];//category值爲數字,例子:'349/417/419','349/413/415','349/413/416'
相關文章
相關標籤/搜索