<?php
/**
* 批量更新-语句
*
数据 $multipleData
表名$table
where条件 $where_arr 默认id
*
数据格式
$multipleData=[
[
'id'=>1,
'name'=>'username',
'pass'=>'pass123'
],
];
*/
function updateBatch($multipleData = [],$table,$where_arr=['id'])
{
try {
if (empty($multipleData)) {
returnInfo(1,'没有数据');
}
$tableName =$table; // 表名
$firstRow = current($multipleData);
//
$updateColumn = array_keys($firstRow);
// 拼接sql语句
$updateSql = "UPDATE " . $tableName . " SET ";
$sets = [];
$bindings = [];
foreach ($updateColumn as $uColumn) {
$setSql = "`" . $uColumn . "` = CASE ";
foreach ($multipleData as $data) {
$setSql .= "W
php实现mysql批量修改
最新推荐文章于 2021-11-24 10:13:26 发布