S
S
Stepan2015-02-09 14:49:34
Yii
Stepan, 2015-02-09 14:49:34

Yii2 in the batchInsert command, for some reason, one empty record is created?

foreach($_POST[PostData] as $key => $value){
                $str = strpos($key, "_");
                $key = substr($key, 0, $str);

                $postData->data_type = $key;
                $postData->post_data = $value;
                $postData->post_id;

                $rows[] = [
                    'post_id' => $postData->post_id,
                    'data_type' => $postData->data_type,
                    'post_data' => $postData->post_data
                ];
            }

            array_shift($rows);

            Yii::$app->db->createCommand()->batchInsert($postData::tableName(), ['post_id', 'data_type', 'post_data'], $rows)->execute();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question