commands/SqlController.php
/**
     * This command echoes what you have entered as the message.
     * @param string $message the message to be echoed.
     * @return int Exit code
     */
This command echoes what you have entered as the message.
@param string $message the message to be echoed.
@return int Exit code
This command echoes what you have entered as the message . @param string $message the message to be echoed . @return int Exit code
public function actionInsertValuesToCarsTable()
    {
        $valuesToBrands = [
          ['Lexus'],
          ['Toyota']
        ];
        $valuesToModels = [
          ['1', 'ES'],
          ['1', 'GX'],
          ['2', 'Camry'],
          ['2', 'Corolla']
        ];
        $valuesToEngines = [
          ['Бензин'],
          ['Дизель'],
          ['Гибрид']
        ];
        $valuesToWheelDrives = [
          ['Передний'],
          ['Задний']
        ];
        $values = [
          ['1', '1', '1'],
          ['1', '2', '1'],
          ['1', '3', '1'],
          ['1', '1', '2'],
          ['1', '2', '2'],
          ['1', '3', '2'],
          ['2', '1', '1'],
          ['2', '2', '1'],
          ['2', '3', '1'],
          ['2', '1', '2'],
          ['2', '2', '2'],
          ['2', '3', '2'],
          ['3', '1', '1'],
          ['3', '2', '1'],
          ['3', '3', '1'],
          ['3', '1', '2'],
          ['3', '2', '2'],
          ['3', '3', '2'],
          ['4', '1', '1'],
          ['4', '2', '1'],
          ['4', '3', '1'],
          ['4', '1', '2'],
          ['4', '2', '2'],
          ['4', '3', '2']
        ];
        $result = Yii::$app->db->createCommand()->batchInsert('data_Brands', ['brand'], $valuesToBrands)->execute();
        $result = Yii::$app->db->createCommand()->batchInsert('data_Models', ['brand_id', 'model'], $valuesToModels)->execute();
        $result = Yii::$app->db->createCommand()->batchInsert('data_Engines', ['engine'], $valuesToEngines)->execute();
        $result = Yii::$app->db->createCommand()->batchInsert('data_Wheel_drives', ['wheel_drive'], $valuesToWheelDrives)->execute();
        $result = Yii::$app->db->createCommand()->batchInsert('cars', ['model_id', 'engine_id', 'wheel_drive_id'], $values)->execute();
        return ExitCode::OK;
    }
public function actionInsertValuesToCarsTable ( ) { $ valuesToBrands = [ [ 'Lexus' ] , [ 'Toyota' ] ] ; $ valuesToModels = [ [ '1' , 'ES' ] , [ '1' , 'GX' ] , [ '2' , 'Camry' ] , [ '2' , 'Corolla' ] ] ; $ valuesToEngines = [ [ 'Бензин'], [ 'Дизель'], [ 'Гибрид'] ] ; $ valuesToWheelDrives = [ [ 'Передний'], [ 'Задний'] ] ; $ values = [ [ '1' , '1' , '1' ] , [ '1' , '2' , '1' ] , [ '1' , '3' , '1' ] , [ '1' , '1' , '2' ] , [ '1' , '2' , '2' ] , [ '1' , '3' , '2' ] , [ '2' , '1' , '1' ] , [ '2' , '2' , '1' ] , [ '2' , '3' , '1' ] , [ '2' , '1' , '2' ] , [ '2' , '2' , '2' ] , [ '2' , '3' , '2' ] , [ '3' , '1' , '1' ] , [ '3' , '2' , '1' ] , [ '3' , '3' , '1' ] , [ '3' , '1' , '2' ] , [ '3' , '2' , '2' ] , [ '3' , '3' , '2' ] , [ '4' , '1' , '1' ] , [ '4' , '2' , '1' ] , [ '4' , '3' , '1' ] , [ '4' , '1' , '2' ] , [ '4' , '2' , '2' ] , [ '4' , '3' , '2' ] ] ; $ result = Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( 'data_Brands' , [ 'brand' ] , $ valuesToBrands ) -> execute ( ) ; $ result = Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( 'data_Models' , [ 'brand_id' , 'model' ] , $ valuesToModels ) -> execute ( ) ; $ result = Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( 'data_Engines' , [ 'engine' ] , $ valuesToEngines ) -> execute ( ) ; $ result = Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( 'data_Wheel_drives' , [ 'wheel_drive' ] , $ valuesToWheelDrives ) -> execute ( ) ; $ result = Yii :: $ app -> db -> createCommand ( ) -> batchInsert ( 'cars' , [ 'model_id' , 'engine_id' , 'wheel_drive_id' ] , $ values ) -> execute ( ) ; return ExitCode :: OK ; }
This command echoes what you have entered as the message.
This command echoes what you have entered as the message .
// if (!$result) return ExitCode::UNSPECIFIED_ERROR;