Welcome Guest, Not a member yet? Register   Sign In
affected_rows() returning strange results
#1

[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);

function write_props($data)
{
    $this->db->insert_batch("immo_props", $data);
    return $this->db->affected_rows();
}

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!
#2

[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.
#3

[eluser]stef25[/eluser]
That would explain things. So there is no way of getting the number of rows inserted with insert_batch() ?
#4

[eluser]Nisha S.[/eluser]
I think, if affected rows = (sizeof($data) % 100) then you can assume all data inserted.
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB