EllisLab text mark
Advanced Search
     
Active Record insert() multiple rows at once
Posted: 21 October 2008 09:51 AM   [ Ignore ]
Avatar
Joined: 2008-08-28
22 posts

Is it possible?

 
Posted: 21 October 2008 09:56 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-28
22 posts

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

 
Posted: 21 October 2008 10:06 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

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

 
Posted: 21 October 2008 04:13 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-13
70 posts

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.

 
Posted: 21 October 2008 04:19 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-28
22 posts

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

 
Posted: 21 October 2008 06:01 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-13
70 posts

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.

 
Posted: 22 October 2008 04:46 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-07-28
511 posts

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 ~

 
Posted: 22 October 2008 05:49 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-28
22 posts

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