标签:批量更新mysql
$display_order = [$this->data[‘user_id‘]=>‘1‘, $this->token_info[‘id‘]=>‘0‘]; $params = array_keys($display_order); $place_holders = implode(‘,‘, array_fill(0, count($params), ‘?‘)); $sql = "UPDATE home_users SET is_admin = CASE user_id "; foreach ($display_order as $user_id => $is_admin) { $sql .= sprintf("WHEN %d THEN ‘%s‘ ", $user_id, $is_admin); } $sql .= "END WHERE user_id IN ($place_holders) AND home_id = ?"; $params[] = $this->data[‘home_id‘]; Model::home_users()->executeBySql($sql,$params);
标签:批量更新mysql
原文地址:http://11873993.blog.51cto.com/11863993/1875403