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

Can anyone explain why this statement:
print $res . " rows inserted when sizeof(data) is " . sizeof($data) ;

prints out
30 rows inserted when sizeof(data) is 130

Relevant 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:

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

65 rows inserted when sizeof(data) is 65

And a 4th test shows

8 rows inserted when sizeof(data) is 108


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

That would explain things. So there is no way of getting the number of rows inserted with insert_batch() ?

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

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