$whereIn = rtrim(str_repeat('?,', count($whereIn)), ','); $sql .= ' WHERE `' . $conditionColumn . '` IN (' . $whereIn . ')';
DB::update($sql, $bindings); }
为了防止 SQL 注入,因此使用了参数绑定的写法。
封装出来的 SQL 语句如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
UPDATE table_name SET`column1` = CASE `condition_column` WHEN condition_value1 THEN update_value1 WHEN condition_value2 THEN update_value2 END, `column2` = CASE `condition_column` WHEN condition_value1 THEN update_value3 WHEN condition_value2 THEN update_value4 END WHERE `condition_column`IN ( condition_value1, condition_value2, condition_value3...)