我对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]);
}发布于 2022-03-24 08:00:15
尝尝这个,
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://stackoverflow.com/questions/71598617
复制相似问题