What potential pitfalls should be considered when using multiple databases in PHP for calculations?

One potential pitfall when using multiple databases in PHP for calculations is ensuring data consistency across the databases. To address this, transactions can be used to ensure that all database operations are completed successfully before committing the changes.

// Start a transaction
$db1->beginTransaction();
$db2->beginTransaction();

// Perform database operations

// Commit the changes
$db1->commit();
$db2->commit();