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.