Mysql count number of records

broken image
broken image

We can use the fetchColumn() method available in PDO to count the table’s rows. PDO is one of the object-oriented ways to connect the database with the PHP server. Use fetchColumn() Method of PDO to Count the Total Number of Rows in a MySQL Table The use of the prepared statement in this method makes it safe from the vulnerability of SQL injection. This method follows the complete object-oriented practice to connect the database and count the total number of rows. We will demonstrate a way to count all the rows from a table using PHP’s num_rows property.

broken image

However, the rest of the process is done procedurally.

broken image

This method uses an object-oriented way to establish the database connection with the server using the mysqli() function. We will demonstrate another method to count all rows from a table using the mysqli_num_rows() function.

broken image