diff --git a/Command.php b/Command.php index 8f2de37..ee2a6c1 100644 --- a/Command.php +++ b/Command.php @@ -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); + } }