ekerazha
(Ekerazha)
November 19, 2013, 12:02pm
1
In Yii, is there a method which returns the number of affected rows from most recent query?
Something like
$this->db->affected_rows()
in CodeIgniter ( http://ellislab.com/...se/helpers.html ).
I looked at CDbConnection methods but I couldn’t find anything.
Thanks.
Some methods like updateAll, deleteAll return this number as a result.
Internally they just return $command->execute();
redguy
(Maciej Lizewski)
November 19, 2013, 12:25pm
3
read: http://www.yiiframework.com/doc/guide/1.1/en/database.dao
A SQL statement is executed via CDbCommand in one of the following two ways:
execute(): performs a non-query SQL statement, such as INSERT, UPDATE and DELETE. If successful, it returns the number of rows that are affected by the execution.
so:
$affected_rows = Yii::app()->db->createCommand( 'UPDATE ...' )->execute();
ekerazha
(Ekerazha)
November 19, 2013, 1:26pm
4
That’s too easy But I don’t want to execute a command/query, I need the number of affected rows from the most recent query (executed in the past without explicitly saving the number of rows).