![]() |
Active Record insert() multiple rows at once - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Active Record insert() multiple rows at once (/showthread.php?tid=12487) |
Active Record insert() multiple rows at once - El Forum - 10-21-2008 [eluser]meglio[/eluser] Is it possible? Active Record insert() multiple rows at once - El Forum - 10-21-2008 [eluser]meglio[/eluser] 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 Active Record insert() multiple rows at once - El Forum - 10-21-2008 [eluser]xwero[/eluser] You are right you can't insert multiple rows using one query. Active Record insert() multiple rows at once - El Forum - 10-21-2008 [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. Active Record insert() multiple rows at once - El Forum - 10-21-2008 [eluser]meglio[/eluser] This is useful, but I'm sure that one query for all rows is more right solution (eg, do not use foreach loop). Active Record insert() multiple rows at once - El Forum - 10-21-2008 [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. Active Record insert() multiple rows at once - El Forum - 10-22-2008 [eluser]drewbee[/eluser] 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. Active Record insert() multiple rows at once - El Forum - 10-22-2008 [eluser]meglio[/eluser] Yes, thanks. That is how I'm doing it - I'm building my own query and then running it using db->query(). |