Skip to content

Commit

Permalink
fix:database:解决sql异常时rowCount再次抛出异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed Sep 1, 2021
1 parent 407cd67 commit a35bcef
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/database/src/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ public function execute(): ConnectionInterface
$this->sqlData[3] = $time;

// 缓存常用数据,让资源可以提前回收
if (!isset($ex) && ($this->driver->pool && !$this instanceof Transaction)) {
if (isset($ex)) {
// 有异常: 使用默认值, 不调用 driver, statement
$this->lastInsertId = '';
$this->rowCount = 0;
} elseif ($this->driver->pool && !$this instanceof Transaction) {
// 有pool: 提前缓存 lastInsertId, rowCount 让连接提前归还
try {
if (stripos($this->sql, 'INSERT INTO') !== false) {
$this->lastInsertId = $this->driver->instance()->lastInsertId();
Expand Down

0 comments on commit a35bcef

Please sign in to comment.