Jul
05
2016
thinkphp更新数据库的五种方法
作者:
绝缘体.. 发布:
2016-07-05 14:25 分类:
未分类 阅读:
抢沙发
thinkphp更新数据库的五种方法。
第一种方法:
$模型->where(‘id=1’)->save($data);
第二种方法:
$模型->where(‘id=1’)->data($data)->save();
第三种方法:
$模型->create();
$模型->save();
表单中必须包含一个以主键为名称的隐藏域
第四种方法:
$模型->where(‘id=5’)->setField(‘name’,’ThinkPHP’);
$模型->where(‘id=5’)->setField(array(‘name’,’email’),array(‘TP’,’TP@163.com’));
//第四种方法,传数组时候,我实现不了。。。
第五种方法:
$模型->setInc(‘score’,’id=5′,3); // 积分加3
$模型->setInc(‘score’,’id=5′); // 积分加1
$模型->setDec(‘score’,’id=5′,5); // 积分减5
$模型->setDec(‘score’,’id=5′); // 积分减1
微信扫一扫,打赏作者吧~