简体   繁体   中英

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

Values of $client_ids is:

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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