How can the rowCount() method in PDO be utilized to check for the number of affected rows in a database operation?

To check the number of affected rows in a database operation using PDO, you can utilize the `rowCount()` method. After executing a query using PDO, you can call `rowCount()` on the PDOStatement object to retrieve the number of rows affected by the operation. This can be useful for verifying the success of an INSERT, UPDATE, DELETE, or other database operation.

// Execute a query using PDO
$stmt = $pdo->prepare("UPDATE users SET name = :name WHERE id = :id");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':id', $id);
$stmt->execute();

// Check the number of affected rows
$affectedRows = $stmt->rowCount();
echo "Number of affected rows: " . $affectedRows;