$stmt = $pdo->prepare('UPDATE users SET name = :name WHERE id = :id'); $stmt->execute(['name' => 'John Doe', 'id' => 1]); $affectedRows = $stmt->affectedRows(); echo $affectedRows; // Output: 1
$stmt = $pdo->prepare('DELETE FROM users WHERE id = :id'); $stmt->execute(['id' => 1]); $affectedRows = $stmt->affectedRows(); echo $affectedRows; // Output: 1The affectedRows function is a part of the PDO library in PHP, which is a database abstraction layer that allows developers to work with different types of databases using the same set of functions.