将数组传入Laravel DB::Select using 'IN' for MariaDB [duplicate]

ego6inou  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(93)

此问题已在此处有答案

How can I bind an array of strings with a mysqli prepared statement?(7个回答)
上个月关门了。
我有一个数组,比如$array,我想传递到一个使用Laravel DB:select方法执行的查询中,例如:
$results=DB::select(“select * from table where id in?“,[$array])
我该怎么做?像上面这样传入给我一个 * 数组到字符串转换 * 错误。
MariaDB
我已经看到了这个Laravel 4: DB::select with IN statment,它不足以满足我的需求(“使用适当的查询”)。

hxzsmxv2

hxzsmxv21#

使用完整的query builder,而不仅仅是选择查询:

$results = DB::table('table_name')
       ->whereIn('id',[1,2,3,4])
       ->get();

相关问题