What are some best practices for debugging SQL queries in PHP to ensure that the correct data is being targeted for deletion?

When debugging SQL queries in PHP to ensure the correct data is being targeted for deletion, it is important to echo or var_dump the SQL query being executed to verify its accuracy. Additionally, using placeholders in the query and binding parameters can help prevent SQL injection and ensure the correct data is being targeted. Finally, testing the query in a SQL client or tool before executing it in PHP can help identify any issues.

// Debugging SQL query for deletion in PHP
$sql = "DELETE FROM table_name WHERE id = :id";
$stmt = $pdo->prepare($sql);
$id = 123; // example ID to be deleted
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
echo $sql; // Output the SQL query for verification
$stmt->execute();