Skip to content

Commit a35bcef

Browse files
committed
fix:database:解决sql异常时rowCount再次抛出异常的问题
1 parent 407cd67 commit a35bcef

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/database/src/AbstractConnection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ public function execute(): ConnectionInterface
193193
$this->sqlData[3] = $time;
194194

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

0 commit comments

Comments
 (0)