What are the potential pitfalls of using foreign key constraints in PHP when updating values?

When updating values in a database table that has foreign key constraints, it's important to ensure that the updated values still satisfy the constraints. This means that you may need to update related tables first before updating the main table, or handle any potential constraint violations that may occur during the update process.

try {
    $pdo->beginTransaction();

    // Update related tables first

    // Update main table

    $pdo->commit();
} catch (PDOException $e) {
    $pdo->rollBack();
    echo "Error updating values: " . $e->getMessage();
}