This commit is contained in:
2024-01-10 18:07:40 +08:00
parent d8b2d1ca2c
commit b647716f1c
+22 -2
View File
@@ -88,9 +88,29 @@ class Command extends Component
* @return mixed
* @throws
*/
public function rowCount(): int
public function rowCount(): mixed
{
return $this->search('rowCount');
$client = $this->connection->getConnection();
try {
if (($prepare = $client->query($this->sql)) === false) {
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $client->errorInfo()[2]);
}
$prepare->execute($this->params);
$prepare->closeCursor();
$this->connection->println($this->sql, $this->params);
return $prepare->rowCount();
} catch (Throwable $throwable) {
if ($this->isRefresh($throwable)) return $this->rowCount();
$errorMsg = $throwable->getMessage() . PHP_EOL . ' Sql: ' . $this->sql . '.' . json_encode($this->params);
$this->getLogger()->failure($errorMsg . PHP_EOL, 'mysql');
return 0;
} finally {
$this->connection->release($client);
}
}