变更
This commit is contained in:
+8
-17
@@ -130,8 +130,8 @@ class Command extends Component
|
||||
*/
|
||||
private function _execute(): bool|int
|
||||
{
|
||||
$pdo = $this->db->getPdo();
|
||||
try {
|
||||
$pdo = $this->db->getPdo();
|
||||
if (!(($prepare = $pdo->prepare($this->sql)) instanceof PDOStatement)) {
|
||||
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ class Command extends Component
|
||||
$result = (int)$pdo->lastInsertId();
|
||||
$prepare->closeCursor();
|
||||
|
||||
$this->db->release($pdo, true);
|
||||
$this->db->release(true);
|
||||
|
||||
return $result == 0 ? true : $result;
|
||||
} catch (\PDOException|\Throwable $throwable) {
|
||||
@@ -152,7 +152,7 @@ class Command extends Component
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
$this->db->release($pdo, true);
|
||||
$this->db->release(true);
|
||||
|
||||
return $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql');
|
||||
}
|
||||
@@ -165,25 +165,16 @@ class Command extends Component
|
||||
*/
|
||||
private function search(string $type): mixed
|
||||
{
|
||||
$pdo = $this->db->getSlaveClient();
|
||||
try {
|
||||
$pdo = $this->db->getSlaveClient();
|
||||
if (($statement = $pdo->query($this->sql)) === false) {
|
||||
throw new Exception($pdo->errorInfo()[1]);
|
||||
}
|
||||
foreach ($this->params as $key => $param) {
|
||||
$statement->bindValue($key, $param);
|
||||
}
|
||||
$data = null;
|
||||
if ($type == self::FETCH_ALL) {
|
||||
$data = $statement->fetchAll(\PDO::FETCH_ASSOC);
|
||||
} else if ($type == self::FETCH) {
|
||||
$data = $statement->fetch(\PDO::FETCH_ASSOC);
|
||||
} else if ($type == self::FETCH_COLUMN) {
|
||||
$data = $statement->fetchColumn(\PDO::FETCH_ASSOC);
|
||||
} else if ($type == self::ROW_COUNT) {
|
||||
$data = $statement->rowCount();
|
||||
}
|
||||
$this->db->release($pdo, false);
|
||||
$data = $statement->{$type}(\PDO::FETCH_ASSOC);
|
||||
$this->db->release(false);
|
||||
return $data;
|
||||
} catch (\Throwable $throwable) {
|
||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
||||
@@ -192,7 +183,7 @@ class Command extends Component
|
||||
return $this->search($type);
|
||||
}
|
||||
|
||||
$this->db->release($pdo, false);
|
||||
$this->db->release(false);
|
||||
|
||||
return $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql');
|
||||
}
|
||||
@@ -201,7 +192,7 @@ class Command extends Component
|
||||
|
||||
private function longExecuteTime($time)
|
||||
{
|
||||
if (($over = microtime(true) - $time) >= 0.50) {
|
||||
if (($over = microtime(true) - $time) >= 0.05) {
|
||||
$this->logger->warning($this->sql . '. use time : ' . $over . 'ms');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user