Laravel + Mysql FIND_IN_SET 逗号分隔存储方式检索

``` //格式说明 #DB::table('表名')->whereRaw('FIND_IN_SET(?,字段名)',[需要查询的字符串])->get(); $type = 2,3; //代码演示 $res_1 = DB::table('article')->whereRaw('FIND_IN_SET(?,type)',[$type])->get();//...
//格式说明
#DB::table('表名')->whereRaw('FIND_IN_SET(?,字段名)',[需要查询的字符串])->get();
$type = 2,3;
//代码演示
$res_1 = DB::table('article')->whereRaw('FIND_IN_SET(?,type)',[$type])->get();//此时得到结果为 id=1的这条数据


$res_2 = Article::whereRaw('FIND_IN_SET(?,type)',[$type])->get();//此时得到结果为 id为3的这条数据
dd($res_1,$res_2);//这两个查询出来的结果是一样的,是指结果集的数据类型有所不用,注意使用$res_2->toArray();打印测试观察结果
  • 发表于 2020-01-04 13:55:51
  • 阅读 ( 165 )