The number of result set rows in the CI that gets read operations + the number of affected rows to get write operations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.