Essence: Read operation, with mysql_num_rows function, write operation with mysql_affected_rows function
mysql_num_rows () returns the number of rows in the result set. This command is valid only for SELECT statements. To get the number of rows affected by the Insert,update or DELETE query, use mysql_affected_rows ().
Methods in CI:
Read operation, gets the number of rows:
$query->num_rows ()
The function will return the number of rows currently requested. In this example, the $query represents the request result object that is generated by the current SQL:
$query = $this->db->query(‘SELECT * FROM my_table‘);
echo $query->num_rows();
Write operation, gets the number of rows affected:
$this->db->affected_rows ()
Displays the number of affected rows, when doing "write\" type queries (INSERT, UPDATE, etc.).
The number of rows affected is displayed when a query is performed on a write operation (insert,update, etc.).
Note:in MySQL "DELETE from TABLE" returns 0 affected rows. The database class has a small hack this allows it to return the correct number of affected rows. By default this hack was enabled but it can be turned off in the database driver file.
Note: The number of rows affected by "DELETE from TABLE" in MySQL will return 0. The database class has a small hack that allows to return the correct number of rows affected. This hack feature is turned on by default, but it can be turned off in the database driver file.
The number of result set rows in the CI that gets read operations + the number of affected rows to get write operations