affected_rows() returning strange results - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: affected_rows() returning strange results (/showthread.php?tid=44250) |
affected_rows() returning strange results - El Forum - 08-09-2011 [eluser]stef25[/eluser] Can anyone explain why this statement: Code: print $res . " rows inserted when sizeof(data) is " . sizeof($data) ; prints out Code: 30 rows inserted when sizeof(data) is 130 Relevant code Code: $res = $this->m_immo->write_props($data); So it seems that affected_rows returns 30 but when I check the DB, 130 rows are inserted which matches the sizeof($data). How come? EDIT: with a second test I'm getting this as output: Code: 85 rows inserted when sizeof(data) is 285 In both cases it just leaves out the first digit. With a 3rd test I get this Code: 65 rows inserted when sizeof(data) is 65 And a 4th test shows Code: 8 rows inserted when sizeof(data) is 108 Stumped! affected_rows() returning strange results - El Forum - 08-09-2011 [eluser]Nisha S.[/eluser] Codeigniter inserts the records batch by batch and each batch contains 100 rows. When you use insert_batch with more than 100 rows, then you will get only the count in last batch which is 30. affected_rows() returning strange results - El Forum - 08-09-2011 [eluser]stef25[/eluser] That would explain things. So there is no way of getting the number of rows inserted with insert_batch() ? affected_rows() returning strange results - El Forum - 08-09-2011 [eluser]Nisha S.[/eluser] I think, if affected rows = (sizeof($data) % 100) then you can assume all data inserted. affected_rows() returning strange results - El Forum - 08-09-2011 [eluser]stef25[/eluser] I'm trying to use this for logging, so I can send an email or write to the DB something like "X rows inserted". This is running on cron and I'd like to keep track of what's happening. |