How can the result of a previously executed INSERT statement be accessed and used in a subsequent DELETE statement in PHP?

To access the result of a previously executed INSERT statement in a subsequent DELETE statement in PHP, you can use the lastInsertId() method provided by PDO. This method retrieves the ID of the last inserted row in a database table, which can then be used in the DELETE statement to target the specific row.

// Assuming $pdo is your PDO object
$pdo->exec("INSERT INTO table_name (column_name) VALUES ('value')");
$insertedId = $pdo->lastInsertId();

$pdo->exec("DELETE FROM table_name WHERE id = $insertedId");