Part of the EllisLab Network
   
 
Active Record insert() multiple rows at once
Posted: 21 October 2008 08:51 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  23
Joined  08-28-2008

Is it possible?

Profile
 
 
Posted: 21 October 2008 08:56 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Avatar
Total Posts:  23
Joined  08-28-2008

I found many thread in this forum where people are asking the same question. I can see that there is no this opportunity now. I’m right?

Anton

Profile
 
 
Posted: 21 October 2008 09:06 AM   [ Ignore ]   [ # 2 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4785
Joined  07-14-2006

You are right you can’t insert multiple rows using one query.

Profile
 
 
Posted: 21 October 2008 03:13 PM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  73
Joined  06-13-2007

There is a work around use an array of arrays that when passed then utilize a foreach loop to insert each record of the array. Note to make sure to check 1 that you passed something and possibly even a count that way you can then retrieve how many records were entered.

Profile
 
 
Posted: 21 October 2008 03:19 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  23
Joined  08-28-2008

This is useful, but I’m sure that one query for all rows is more right solution (eg, do not use foreach loop).

Profile
 
 
Posted: 21 October 2008 05:01 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  73
Joined  06-13-2007

The question was is it possible. And therefore I answered a dry dull no with a way to implement; there is in fact a way for doing everything in programming. As to the usage that would depend entirely on what it would be used for and anyway should be used with discretion and scrutinized before using. Are there better ways of doing things in programming most definitely and always, there are at least 10 ways of doing anything.

Profile
 
 
Posted: 22 October 2008 03:46 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  549
Joined  07-28-2008

Correct. In these instances, I have always just found my self building the full query, then doing the standard $this->db->query().

Please remember, you have to manually escape your strings in this.

 Signature 

~ 4 All the Right Reasons ~

Profile
 
 
Posted: 22 October 2008 04:49 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Avatar
Total Posts:  23
Joined  08-28-2008

Yes, thanks.
That is how I’m doing it - I’m building my own query and then running it using db->query().

Profile