public static function updateAll($attributes, $condition = null)
    {
        if (empty($attributes)) {
            return 0;
        }
        $db = static::getDb();
        $n = 0;
        foreach (self::fetchPks($condition) as $pk) {
            $newPk = $pk;
            $pk = static::buildKey($pk);
            $key = static::keyPrefix() . ':a:' . $pk;
            // save attributes
            $delArgs = [$key];
            $setArgs = [$key];
            foreach ($attributes as $attribute => $value) {
                if (isset($newPk[$attribute])) {
                    $newPk[$attribute] = $value;
                }
                if ($value !== null) {
                    if (is_bool($value)) {
                        $value = (int) $value;
                    }
                    $setArgs[] = $attribute;
                    $setArgs[] = $value;
                } else {
                    $delArgs[] = $attribute;
                }
            }
            $newPk = static::buildKey($newPk);
            $newKey = static::keyPrefix() . ':a:' . $newPk;
            // rename index if pk changed
            if ($newPk != $pk) {
                $db->executeCommand('MULTI');
                if (count($setArgs) > 1) {
                    $db->executeCommand('HMSET', $setArgs);
                }
                if (count($delArgs) > 1) {
                    $db->executeCommand('HDEL', $delArgs);
                }
                $db->executeCommand('LINSERT', [static::keyPrefix(), 'AFTER', $pk, $newPk]);
                $db->executeCommand('LREM', [static::keyPrefix(), 0, $pk]);
                $db->executeCommand('RENAME', [$key, $newKey]);
                $db->executeCommand('EXEC');
            } else {
                if (count($setArgs) > 1) {
                    $db->executeCommand('HMSET', $setArgs);
                }
                if (count($delArgs) > 1) {
                    $db->executeCommand('HDEL', $delArgs);
                }
            }
            $n++;
        }

        return $n;
    }
public static function updateAll($attributes, $condition = null)
    {
        if (empty($attributes)) {
            return 0;
        }
        $db = static::getDb();
        $n = 0;
        foreach (self::fetchPks($condition) as $pk) {
            $newPk = $pk;
            $pk = static::buildKey($pk);
            $key = static::keyPrefix() . ':a:' . $pk;
            
            $delArgs = [$key];
            $setArgs = [$key];
            foreach ($attributes as $attribute => $value) {
                if (isset($newPk[$attribute])) {
                    $newPk[$attribute] = $value;
                }
                if ($value !== null) {
                    if (is_bool($value)) {
                        $value = (int) $value;
                    }
                    $setArgs[] = $attribute;
                    $setArgs[] = $value;
                } else {
                    $delArgs[] = $attribute;
                }
            }
            $newPk = static::buildKey($newPk);
            $newKey = static::keyPrefix() . ':a:' . $newPk;
            
            if ($newPk != $pk) {
                $db->executeCommand('MULTI');
                if (count($setArgs) > 1) {
                    $db->executeCommand('HMSET', $setArgs);
                }
                if (count($delArgs) > 1) {
                    $db->executeCommand('HDEL', $delArgs);
                }
                $db->executeCommand('LINSERT', [static::keyPrefix(), 'AFTER', $pk, $newPk]);
                $db->executeCommand('LREM', [static::keyPrefix(), 0, $pk]);
                $db->executeCommand('RENAME', [$key, $newKey]);
                $db->executeCommand('EXEC');
            } else {
                if (count($setArgs) > 1) {
                    $db->executeCommand('HMSET', $setArgs);
                }
                if (count($delArgs) > 1) {
                    $db->executeCommand('HDEL', $delArgs);
                }
            }
            $n++;
        }

        return $n;
    }
public static function updateAll ( $ attributes , $ condition = null ) { if ( empty ( $ attributes ) ) { return 0 ; } $ db = static :: getDb ( ) ; $ n = 0 ; foreach ( self :: fetchPks ( $ condition ) as $ pk ) { $ newPk = $ pk ; $ pk = static :: buildKey ( $ pk ) ; $ key = static :: keyPrefix ( ) . ':a:' . $ pk ; // save attributes $ delArgs = [ $ key ] ; $ setArgs = [ $ key ] ; foreach ( $ attributes as $ attribute => $ value ) { if ( isset ( $ newPk [ $ attribute ] ) ) { $ newPk [ $ attribute ] = $ value ; } if ( $ value !== null ) { if ( is_bool ( $ value ) ) { $ value = ( int ) $ value ; } $ setArgs [ ] = $ attribute ; $ setArgs [ ] = $ value ; } else { $ delArgs [ ] = $ attribute ; } } $ newPk = static :: buildKey ( $ newPk ) ; $ newKey = static :: keyPrefix ( ) . ':a:' . $ newPk ; // rename index if pk changed if ( $ newPk != $ pk ) { $ db -> executeCommand ( 'MULTI' ) ; if ( count ( $ setArgs ) > 1 ) { $ db -> executeCommand ( 'HMSET' , $ setArgs ) ; } if ( count ( $ delArgs ) > 1 ) { $ db -> executeCommand ( 'HDEL' , $ delArgs ) ; } $ db -> executeCommand ( 'LINSERT' , [ static :: keyPrefix ( ) , 'AFTER' , $ pk , $ newPk ] ) ; $ db -> executeCommand ( 'LREM' , [ static :: keyPrefix ( ) , 0 , $ pk ] ) ; $ db -> executeCommand ( 'RENAME' , [ $ key , $ newKey ] ) ; $ db -> executeCommand ( 'EXEC' ) ; } else { if ( count ( $ setArgs ) > 1 ) { $ db -> executeCommand ( 'HMSET' , $ setArgs ) ; } if ( count ( $ delArgs ) > 1 ) { $ db -> executeCommand ( 'HDEL' , $ delArgs ) ; } } $ n ++ ; } return $ n ; }
Updates the whole table using the provided attribute values and conditions.
For example, to change the status to be 1 for all customers whose status is 2:

~~~
Customer::updateAll(['status' => 1], ['id' => 2]);
~~~

@param array $attributes attribute values (name-value pairs) to be saved into the table
@param array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
Please refer to [[ActiveQuery::where()]] on how to specify this parameter.
@return int the number of rows updated
Updates the whole table using the provided attribute values and conditions . For example to change the status to be 1 for all customers whose status is 2 :