Skip to content

Commit

Permalink
解决断线重连成功后相关错误信息没被重置的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
linvanda committed Jul 18, 2019
1 parent eaa0042 commit 8bee0ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/Connector/CoConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function connect(): bool

$conn = $this->mysql->connect($this->config);

if ($this->mysql->connect_error) {
if (!$conn) {
throw new ConnectException($this->mysql->connect_error, $this->mysql->connect_errno);
}

Expand Down Expand Up @@ -179,6 +179,7 @@ public function lastError(): string

/**
* 失败重连
* @throws ConnectException
*/
private function tryReconnectForQueryFail()
{
Expand All @@ -187,7 +188,17 @@ private function tryReconnectForQueryFail()
}

// 尝试重新连接
return $this->mysql->connect($this->config);
$connRst = $this->connect();

if ($connRst) {
// 连接成功,需要重置以下错误(swoole 在重连成功后并没有重置这些属性)
$this->mysql->error = '';
$this->mysql->errno = 0;
$this->mysql->connect_error = '';
$this->mysql->connect_errno = 0;
}

return $connRst;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/ConnectException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Dev\MySQL\Exception;

class ConnectException extends \Exception
class ConnectException extends DBException
{
//
}
}

0 comments on commit 8bee0ff

Please sign in to comment.