数据更新

简单数据更新

$this->db()->update('user-id-1', [
    'status' => 1,
    'stime' => '2015-05-16'
]);

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

多个条件

$this->db()->where('id', 1)
    ->where('status', 1)
    ->update('user', [
        'status' => 0
    ]);
或者
$this->db()->table('user')
    ->where('id', 1)
    ->where('status', 1)
    ->update([
        'status' => 0
    ]);

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

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

results matching ""

    No results matching ""