操作数据库使用技巧
- 插入并且返回当前ID
- Db::name($this->table)->insertGetId($data);
- 更新数据库某个字段+1
- Db::name($this->table)->where(['id' => $id])->setInc('num', $stockNum);
- 更新数据库某个字段-1
- Db::name($this->table)->where(['id' => $id])->setDec('num', $stockNum);
- 事务处理
-
//事务处理
Db::startTrans();
try {throw new \LogicException(XXX)
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error("错误!{$e->getMessage()}");
}
-
- 后台链表查询
- $this->_query($this->table)->alias('N')->join('member M','M.id=N.mid')->field("M.nickname,N.*")->like('title')->order('update_time DESC')->page();

浙公网安备 33010602011771号