Thinkphp中如何书写按照指定字段同步更新的ORM

群友提出一个问题,如何在更新某个字段的时候同步另一个字段数据过来,即 

update table set column1 =column2 where xxx

写原生SQL当然可行,不过既然有ORM那就应该尝试着封装为ORM,找了找手册,尝试了一下这个

<?php
$res=M('user')->where(array("id"=>2))->save(array(
           "email"=>array("exp","username")
        ));
?>

好了 果然把 email的数据同步为 username的数据了

posted @ 2017-06-19 16:42  李照耀  阅读(627)  评论(0编辑  收藏  举报