数据更新

简单数据更新

  1. $this->db()->update('user-id-1', [
  2. 'status' => 1,
  3. 'stime' => '2015-05-16'
  4. ]);
  5. //特别指定表前缀为u_(假设配置中配置的不为u_)v2.6.5起可用
  6. $this->db()->update('user-id-1', [
  7. 'status' => 1,
  8. 'stime' => '2015-05-16'
  9. ], true, 'u_');

多个条件

  1. $this->db()->where('id', 1)
  2. ->where('status', 1)
  3. ->update('user', [
  4. 'status' => 0
  5. ]);
  6. 或者
  7. $this->db()->table('user')
  8. ->where('id', 1)
  9. ->where('status', 1)
  10. ->update([
  11. 'status' => 0
  12. ]);

更新多个字段,某些字段自增自减/包含运算/mysql函数

  1. $this->db()->update('user-id-1', [
  2. 'status' => 0,
  3. 'count' => ['inc' =>2], //自增2,
  4. 'count2' => ['dec' => 2], //自减2,
  5. 'total' => ['count1' => ['+' => 2]], // `total` = `count1`+2
  6. 'ip' => [
  7. 'func' => ['concat' => ["1", '`username`', '2']]
  8. ] // `ip` = concat(1, `username`, 2) //使用函数需>= v2.5.9.字段名用``引起来
  9. ]);

原文: http://doc.cmlphp.com/devintro/model/mysql/update.html