...
|
...
|
@@ -349,6 +349,26 @@ class DbPool { |
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 验证是否正常连接
|
|
|
* @return bool
|
|
|
* @author:dc
|
|
|
* @time 2024/4/10 10:09
|
|
|
*/
|
|
|
public function ping(){
|
|
|
try {
|
|
|
$query = $this->getClient()->query("select 200;");
|
|
|
if($query->fetchColumn() == 200){
|
|
|
return true;
|
|
|
}
|
|
|
}catch (\Throwable $e){
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @param $cid
|
...
|
...
|
@@ -360,6 +380,13 @@ class DbPool { |
|
|
if(empty(static::$instance[$cid])){
|
|
|
static::$instance[$cid] = new DbPool($cid);
|
|
|
}
|
|
|
|
|
|
if(!static::$instance[$cid]->ping()){
|
|
|
static::$instance[$cid]->close();
|
|
|
|
|
|
static::$instance[$cid] = new DbPool($cid);
|
|
|
}
|
|
|
|
|
|
return static::$instance[$cid];
|
|
|
}
|
|
|
|
...
|
...
|
|