Yii2 Batch Add problem yii framework Yii migrate Yii CreateCommand

Source: Internet
Author: User
Tags bulk insert yii
Add this operation in bulk, the actual development of the said use, it must be used to get, otherwise you see how so many people every day nothing Baidu this Google that, right, living needs AH

We've written about how to delete data in bulk from the GridView in Yii2, of course, focus on how to operate the GridView, today we have to talk about yii2 how to add data in bulk?

There are students shouting, this is not simple, I foreach a loop, each loop inside the data inserted directly into the database, simple rough finished! I wipe, elder brother, if you are with me in a company, I think the probability of seeing you next day is not big!

Words do not say much, say more you scold me, we go to the point, first look at a simple to the pupils know the table structure

  ID name

We are now going to BULK insert 10 data into this data sheet in Yii2

The way we want to be is certainly the following, a SQL how simply directly

INSERT into test (name) VALUES (' Zhangsan '), (' Lisi ');

Analysis is all done, okay, just look at the concrete implementation

        $data = foreach ($names $k $v) {  $data [] = [$v];} Yii::$app$data

I believe that many people are directed at the AR can achieve bulk insertion, the reason is nothing more safe and more convenient operation Bai. But the Official handbook seems to have no, no, no ... Heart is broken, unexpectedly did not, at least I did not find, you found please click on the original to find me and contact me, I also si points need method ah.

But unfortunately, I found an AR associated with the operation method, we share the reference to see what's going on

[Considering the current domestic web site most of the collection of articles very frequently, not to mention the original source, the original author would like to see the original text, in case there are any problems can not update all articles, to avoid misleading! ]

Continue Reading

The above describes the YII2 batch add problem, including the Yii content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.