资讯中心
News
thinkphp更新数据库的五种方法
发布时间:2022-09-27 00:00   您所在的位置: 网站首页 > 新闻资讯 > 经验杂谈
先进种方法:

$模型->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.jianzhan0.com/jingyand/75316.html