diff --git a/Command.php b/Command.php index 8f7c4a9..17279e2 100644 --- a/Command.php +++ b/Command.php @@ -187,15 +187,16 @@ class Command extends Component $result = $client->lastInsertId(); $prepare->closeCursor(); - if (!$client->inTransaction()) { - $this->connection->release($client); - } return $result == 0 ? true : (int)$result; } catch (Throwable $throwable) { if ($this->canReconnect($throwable->getMessage())) { return $this->_execute(); } return $this->error($throwable); + } finally { + if (isset($client) && !$client->inTransaction()) { + $this->connection->release($client); + } } }