When developing web applications, pagination query is one of the very common needs, especially in modules such as backend management systems, comment sections or product lists that need to display a large amount of data. MySQL provides the LIMIT clause for paging, while the PDOStatement::rowCount() method in PDO of PHP can be used to get the number of result sets. If the two are combined properly, it can not only improve the readability of the code, but also significantly optimize query efficiency.
PDOStatement::rowCount