What is the recommended method for counting database entries with PDO in PHP?
When counting database entries with PDO in PHP, it is recommended to use the `rowCount()` method after executing a SELECT query. This method returns the number of rows affected by the last SQL statement, which can be used to count the number of entries retrieved from the database.
// Connect to the database
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
// Prepare and execute a SELECT query
$stmt = $pdo->prepare("SELECT * FROM my_table WHERE column = :value");
$stmt->bindParam(':value', $value);
$stmt->execute();
// Count the number of entries retrieved
$count = $stmt->rowCount();
echo "Number of entries: " . $count;