Talking about the ROWCOUNT function of PDO and the pdorowcount_php tutorial

Source: Internet
Author: User

Talking about the ROWCOUNT function of PDO, talking about Pdorowcount


PDO has a function Pdostatement::rowcount returns the number of rows affected by the previous SQL statement.

The ROWCOUNT function is correct for a delete, INSERT, or UPDATE statement, but is related to the implementation of the database for the SELECT statement. Some databases read all of the result set into memory when executing a SELECT statement, but for a large number of result sets, this is obviously inefficient. Most databases only return part of the result set, and then return the rest of the result set when needed, so that both memory consumption and execution efficiency are optimized. In the latter case, rowcount cannot return the correct number of rows for the result set of the SELECT statement. There are several ways to get the correct number of rows for a select result

1. Use the Fetchall function $q = $db->query ("SELECT ..."); $rows = $q->fetchall (); $rowCount = count ($rows);
2. Use the SQL count function $q = $db->query ("SELECT count (*) from DB;"); $rows = $q->fetch (); $rowCount = $rows [0];

Obviously, the second method is more efficient.

The above mentioned is the whole content of this article, I hope you can like.

http://www.bkjia.com/PHPjc/1019077.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019077.html techarticle talking about the rowcount function of PDO, Pdorowcount PDO has a function Pdostatement::rowcount returns the number of rows affected by the previous SQL statement. RowCount function for Delete, INSERT, or UPDATE statement ...

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