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
原文地址:http://www.xazcit.com/thinkphp-updated-database-of-five-methods/
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: TP3.2.3学习(一) | 配置文件
- 下一篇: Ambari卸载已安装的服务组件