您的位置:首页 > 编程语言 > PHP开发

thinkphp更新数据库的五种方法

2013-12-23 15:05 337 查看
第一种方法:

$模型->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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: