If during a database transaction (after $pdo->beginTransaction) a fatal exception is thrown (but not a PDOException), what happens? Is the transaction rolled back automatically, or is it left open indefinitely?

Is the answer the same if there is a crash during a transaction?

I am worried about having rows locked indefinitely or leaving connections open indefinitely.

Transactions are rolled back when the connection to the db is closed and the connection is automatically closed whenever the PHP script ends, also when fatal errors occur. No need to worry about connections or transactions being open indefinitely.