Welcome Guest, Not a member yet? Register   Sign In
Number of rows deleted from database (activerecords)
#1

[eluser]Unknown[/eluser]
Hi,

Is it possible to get number of rows delete query affected with activerecords?
I've tried num_rows(), but no luck. Throws up an error.

The code itself is pretty straightforward;

Code:
return $this->db
    ->where($conditions)
    ->delete('mytable');

Thanks in advance!
#2

[eluser]mddd[/eluser]
num_rows is to find the number of rows in a select statement.
To find the number of affected rows in 'write' type statements, use affected_rows.
This is a query you do to the database, not to the query result. So use:

Code:
$this->db->where($conditions)->delete('mytable');
return $this->db->affected_rows();
#3

[eluser]Unknown[/eluser]
Ah, yes. Stupid me Smile
Thanks a lot, that indeed did it.




Theme © iAndrew 2016 - Forum software by © MyBB