首页 > 其他 > 详细

多条间多数据修改公用方法

时间:2019-09-01 20:06:55      阅读:81      评论:0      收藏:0      [点我收藏+]

 

    //多条间多数据修改
    public function updateBatchStitching($table,$data,$fields,$primary){
        $aSql = ‘UPDATE ‘ . $table . ‘ SET ‘;
        foreach ($fields as $field){
            $str1 = ‘`‘ . $field . ‘` = CASE ‘ . $primary . ‘ ‘;
            foreach ($data as $key => $value){
                $str1 .= ‘WHEN \‘‘ . $value[$primary] . ‘\‘ THEN \‘‘ . $value[$field] . ‘\‘ ‘;
            }
            $str1 .= ‘END , ‘;
            $aSql .= $str1;
        }
        $aSql = substr($aSql,0,strlen($aSql)-2);
        $endStr = ‘WHERE ‘ . $primary . ‘ IN (‘;
        foreach ($data as $key => $value){
            $endStr .= ‘\‘‘.$value[$primary] . ‘\‘,‘;
        }
        $endStr = substr($endStr,0,strlen($endStr)-1);
        $endStr .= ‘)‘;
        $aSql .= $endStr;
        return $aSql;
    }

  

多条间多数据修改公用方法

原文:https://www.cnblogs.com/vickystudy/p/11443216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!