Related questions, but not quite what I'd like to know, as I'm curious about the specific behavior of the PHP mysqli
lib/functions:
- What happens when a connection is closed mid-transaction?
- What happens to an uncommitted transaction when the connection is closed?
Suppose I have some code like so (disregarding whether its good or bad practice):
# ... some code
$conn = new mysqli('localhost', 'widget-manager', 'secret-widgets', 'widgets');
$conn->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
if (false) {
$sql = "UPDATE widgets SET widget_num = 1 WHERE widget_id = 5";
$res = $conn->query($sql);
if ($res) {
$conn->commit();
} else {
$conn->rollback();
}
}
$conn->close();
# ... some more code
The if
which contains the commits and rollbacks would be skipped and the mysqli
connection would be closed after the transaction was started, but before a commit or rollback was invoked.
Would the transaction also be immediately destroyed/ended/whatever-the-proper-term, or would it remain and possibly block other queries from other services?