From 64641cbd766366941c3da0b059efc42859d09fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=91=D0=B0=D0=B3=D0=B0=D0=B5?= =?UTF-8?q?=D0=B2?= Date: Sat, 2 Nov 2013 10:42:14 +0500 Subject: [PATCH] Add batchInsert method to yii\db\Migration --- framework/yii/db/Migration.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/framework/yii/db/Migration.php b/framework/yii/db/Migration.php index 307b02a..37fdf3f 100644 --- a/framework/yii/db/Migration.php +++ b/framework/yii/db/Migration.php @@ -158,6 +158,21 @@ class Migration extends \yii\base\Component } /** + * Creates and executes an batch INSERT SQL statement. + * The method will properly escape the column names, and bind the values to be inserted. + * @param string $table the table that new rows will be inserted into. + * @param array $columns the column names. + * @param array $rows the rows to be batch inserted into the table + */ + public function batchInsert($table, $columns, $rows) + { + echo " > insert into $table ..."; + $time = microtime(true); + $this->db->createCommand()->batchInsert($table, $columns, $rows)->execute(); + echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; + } + + /** * Creates and executes an UPDATE SQL statement. * The method will properly escape the column names and bind the values to be updated. * @param string $table the table to be updated.