Skip to content

Commit ac7c41b

Browse files
committed
优化PDOConnection类query和execute方法 不依赖Query
1 parent e39ccf2 commit ac7c41b

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/db/PDOConnection.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ public function getCursor(BaseQuery $query, string $sql, $model = null, $conditi
686686
*/
687687
public function query(string $sql, array $bind = [], bool $master = false): array
688688
{
689-
return $this->pdoQuery($this->newQuery()->bind($bind), $sql, $master);
689+
$this->getPDOStatement($sql, $bind, $master);
690+
return $this->getResult();
690691
}
691692

692693
/**
@@ -701,7 +702,25 @@ public function query(string $sql, array $bind = [], bool $master = false): arra
701702
*/
702703
public function execute(string $sql, array $bind = []): int
703704
{
704-
return $this->pdoExecute($this->newQuery()->bind($bind), $sql, true);
705+
$this->getPDOStatement($sql, $bind, true);
706+
return $this->PDOStatement->rowCount();
707+
}
708+
709+
/**
710+
* 获取最近插入的ID.
711+
* @param string $sequence 自增序列名
712+
*
713+
* @return mixed
714+
*/
715+
public function getAutoID(?string $sequence = null)
716+
{
717+
try {
718+
$insertId = $this->linkID->lastInsertId($sequence);
719+
} catch (\Exception $e) {
720+
$insertId = '';
721+
}
722+
723+
return $insertId;
705724
}
706725

707726
/**
@@ -1747,13 +1766,7 @@ public function getLastSql(): string
17471766
*/
17481767
public function getLastInsID(BaseQuery $query, ?string $sequence = null)
17491768
{
1750-
try {
1751-
$insertId = $this->linkID->lastInsertId($sequence);
1752-
} catch (\Exception $e) {
1753-
$insertId = '';
1754-
}
1755-
1756-
return $this->autoInsIDType($query, $insertId);
1769+
return $this->autoInsIDType($query, $this->getAutoID($sequence));
17571770
}
17581771

17591772
/**

0 commit comments

Comments
 (0)