public function batchInsert() { echo "Executing query start\n"; $query = "SELECT COUNT(*) FROM `" . FlightCache::model()->tableName() . "`"; $beforeFlights = Yii::app()->db->createCommand($query)->queryScalar(); $query = "SELECT COUNT(*) FROM `" . HotelCache::model()->tableName() . "`"; $beforeHotels = Yii::app()->db->createCommand($query)->queryScalar(); $queryFlight = "\r\n LOAD DATA INFILE '" . $this->fullFlightPath . "'\r\n REPLACE\r\n INTO TABLE `" . FlightCache::model()->tableName() . "`\r\n FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"; Yii::app()->db->createCommand($queryFlight)->execute(); $queryHotel = "\r\n LOAD DATA INFILE '" . $this->fullHotelPath . "'\r\n REPLACE\r\n INTO TABLE `" . HotelCache::model()->tableName() . "`\r\n FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"; Yii::app()->db->createCommand($queryHotel)->execute(); $query = "SELECT COUNT(*) FROM `" . FlightCache::model()->tableName() . "`"; $afterFlights = Yii::app()->db->createCommand($query)->queryScalar(); $query = "SELECT COUNT(*) FROM `" . HotelCache::model()->tableName() . "`"; $afterHotels = Yii::app()->db->createCommand($query)->queryScalar(); echo "Executing queries end\n\n"; echo "Before flights: {$beforeFlights}\n"; echo "After flights: {$afterFlights} \n"; echo "Inserted flights: " . ($afterFlights - $beforeFlights) . "\n\n"; echo "Before hotels: {$beforeHotels}\n"; echo "After hotels: {$afterHotels} \n"; echo "Inserted hotels: " . ($afterHotels - $beforeHotels) . "\n\n"; $stat = Yii::app()->db->getStats(); unlink($this->fullFlightPath); unlink($this->fullHotelPath); }
public function actionClean() { $query = "DELETE FROM " . FlightCache::model()->tableName() . " WHERE `dateFrom` < NOW();"; $deleted = Yii::app()->db->createCommand($query)->execute(); echo "Deleted flight rows: " . $deleted . "\n"; $query = "DELETE FROM " . HotelCache::model()->tableName() . " WHERE `dateFrom` < NOW();"; $deleted = Yii::app()->db->createCommand($query)->execute(); echo "Deleted hotel rows: " . $deleted . "\n"; }