What are the differences between using mysql_affected_rows() and rowCount() in PHP for retrieving the number of affected rows after an update statement?

When retrieving the number of affected rows after an update statement in PHP, it is recommended to use the PDO rowCount() method instead of the deprecated mysql_affected_rows() function. PDO provides a more flexible and secure way to interact with databases, and rowCount() is specifically designed for retrieving the number of affected rows after an update operation.

// Using PDO to execute an update statement and retrieve the number of affected rows
try {
    $pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
    
    $stmt = $pdo->prepare("UPDATE mytable SET column = :value WHERE id = :id");
    $stmt->bindParam(':value', $value);
    $stmt->bindParam(':id', $id);
    $stmt->execute();
    
    $affectedRows = $stmt->rowCount();
    
    echo "Number of affected rows: " . $affectedRows;
} catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}