Welcome Guest, Not a member yet? Register   Sign In
Active Record insert() multiple rows at once

Is it possible?

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?


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

[eluser]Christopher Blankenship[/eluser]
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.

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

[eluser]Christopher Blankenship[/eluser]
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.

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.

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

Theme © iAndrew 2016 - Forum software by © MyBB