我是 mysql 查詢的新手,我有一個查詢,status in ('php','laravel','apiato')如果我像這樣使用它,它將搜索陣列中的所有專案,現在我必須向陣列添加更多值而不是傳遞字串,我從中創建了一個常量檔案檔案我想發送一個陣列,它拋出了一個例外Array To string Conversion
public function getALlData(){
$array = BooksConstants::Status_constants;
DB::select("SELECT count(1) as total_transactions from books where books.account_id in ('$this->account_ids') and DATE(created_at) between ? and ? and status in $array ", [$fromDate, $toDate]);
}
uj5u.com熱心網友回復:
嘗試這個,
public function getALlData(){
$array = BooksConstants::Status_constants;
DB::select("SELECT count(1) as total_transactions from books where books.account_id in ('$this->account_ids') and DATE(created_at) between ? and ? and status in ('" . implode("','", array_map('trim', $array)) ."') ", [$fromDate, $toDate]);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/448889.html
上一篇:匯出mysql資料庫表
