$stmt = $pdo->prepare('DELETE FROM users WHERE id = ?'); $stmt->bindValue(1, $user->id, PDO::PARAM_INT); $stmt->execute(); if (($rowCount = $stmt->rowCount()) > 1) { throw new \RuntimeException( "Expected to delete 1 row, but deleted {$rowCount} rows"); } 1件削除
$stmt = $pdo->prepare('DELETE FROM users WHERE id = ?'); $stmt->bindValue(1, $user->id, PDO::PARAM_INT); $stmt->execute(); if (($rowCount = $stmt->rowCount()) > 1) { throw new \RuntimeException( "Expected to delete 1 row, but deleted {$rowCount} rows"); } 1件削除
'name' => ..., 'email' => ..., ]; // DTO class UserDto { public function __construct( public int $id, public string $name, public string $email, ) {} }