public static function lazySave() { if (self::$needSave) { $connection = Yii::app()->db; $values = array(); $attrs = array('id', 'name', 'stars', 'cityId', 'countryId', 'rating', 'minPrice'); foreach (self::$hotelDbs as $hotelDb) { if ($hotelDb->id) { $vals = array(); foreach ($attrs as $attrName) { $attrVal = $hotelDb->getAttribute($attrName); if ($attrVal) { $vals[] = "'" . addslashes($attrVal) . "'"; } else { $vals[] = 'NULL'; } } $values[] = "(" . implode(',', $vals) . ")"; } } $sql = 'INSERT INTO hotel (' . implode(',', $attrs) . ') VALUES ' . implode(',', $values); //$sql .= " (".implode(',',$in).")"; $sql .= " ON DUPLICATE KEY UPDATE rating=VALUES(rating),minPrice=VALUES(minPrice)"; $command = $connection->createCommand($sql); $command->execute(); self::$needSave = false; } }