场景:
访问地址:http://xxx.com/index.php?m=home&c=demo&a=test&keyword=3B9D082D,3B9D082A,3B9D0903,3B9D082C
把接收到参数(keyword),在sql查询中,使用in会自动加上引号
php应用代码:
$param = $this->param(); $keyword = $param['keyword']; $sql = "SELECT * from mes_goods_warehouse_lists WHERE FIND_IN_SET(barcode,'{$keyword}')"; $res = Db::query($sql); print_r($res);
原始sql代码:
SELECT * from mes_goods_warehouse_lists WHERE FIND_IN_SET(barcode,'3B9D082D,3B9D082A');
// 相当于下面代码
SELECT * from mes_goods_warehouse_lists WHERE barcode in('3B9D082D','3B0D082A')