thinkphp更新数据库的五种方法

来源:互联网 发布:软件助手下载 编辑:程序博客网 时间:2024/05/29 13:24

第一种方法:

$模型->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


原文地址:http://www.xazcit.com/thinkphp-updated-database-of-five-methods/

0 0
原创粉丝点击