$sql = "UPDATE users SET email = 'newemail@example.com' WHERE id = 1"; $result = mysqli_query($conn, $sql); if (mysqli_affected_rows($conn) > 0) { echo "Update successful!"; } else { echo "No rows were updated."; }
$sql = "DELETE FROM orders WHERE id = 5"; $result = $pdo->exec($sql); if ($pdo->affected_rows() > 0) { echo "Order deleted successfully!"; } else { echo "No rows were deleted."; }In this example, we are deleting an order with ID 5 from the `orders` table using PDO. We then use the `affected_rows` method of the PDO object to check if any rows were affected by the delete query. If the number of affected rows is greater than 0, we display a success message. Otherwise, we display a message indicating that no rows were deleted. Package/Library: PDO