f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
206 stars 89 forks source link

DB\SQL: Check for active transaction before rollback/commit #313

Closed Alanaktion closed 3 years ago

Alanaktion commented 3 years ago

As PHP 8 reports the actual transaction state in the MySQL PDO driver, running multiple statements with DB\SQL::exec() can break if any of those statements causes the transaction to end early (as is the case in things like schema changes). This was silently ignored in PHP 5/7, but under PHP 8 it can break without these additional checks.

This is not the only way to handle this change, and it may be something better left to the end-user. It may also affect performance and potentially break some behavior, though I didn't notice any major differences.

User code could instead just call DB\SQL::exec() in a loop when transactions cannot not be used, but this did affect projects I maintain when running under PHP 8 so I figured I'd open a PR for feedback.