简体   繁体   English

Laravel 在 DB::select() 上的值中绑定

[英]Laravel Bind where in values on DB::select()

Here's the query that fetches the list of clients where id has values of $client_ids这是获取 id 值为$client_ids的客户端列表的查询

Values of $client_ids is: $client_ids的值为:

array:25 [▼
  0 => "PC00003"
  1 => "PC00015"
  2 => "PC00017"
]
DB::select(DB::raw("SELECT * FROM clients WHERE client_id IN (:client_ids)",
            array('client_ids'=>$client_ids)
           )
);

And the error is:错误是:

SQLSTATE[HY000]: General error: 2031 (SQL: SELECT * FROM clients WHERE client_id IN (:client_ids))

this will work for you.这对你有用。

$results = DB::table('clients')->whereIn('client_id', $client_ids)->get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM