| 
...
 | 
...
 | 
@@ -37,6 +37,11 @@ trait DbQuery { | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     public function getClient()
 | 
| 
 | 
 | 
     {
 | 
| 
 | 
 | 
         // 读取连接齐前 检查
 | 
| 
 | 
 | 
 //        if(isset(static::$pool) && !$this->ping()){
 | 
| 
 | 
 | 
 //            $this->close();
 | 
| 
 | 
 | 
 //            $this->client = static::$pool->get();
 | 
| 
 | 
 | 
 //        }
 | 
| 
 | 
 | 
         return $this->client;
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
...
 | 
...
 | 
@@ -387,51 +392,45 @@ trait DbQuery { | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 事务开启
 | 
| 
 | 
 | 
      * 事务处理
 | 
| 
 | 
 | 
      * @param \Closure $call 闭包函数 返回true表示提交事务 返回false/抛出异常表示回滚事务
 | 
| 
 | 
 | 
      * @param mixed ...$params 传递给闭包函数的参数
 | 
| 
 | 
 | 
      * @author:dc
 | 
| 
 | 
 | 
      * @time 2023/2/17 11:35
 | 
| 
 | 
 | 
      */
 | 
| 
 | 
 | 
     public function transaction(){
 | 
| 
 | 
 | 
     public function transaction(\Closure $call, ...$params){
 | 
| 
 | 
 | 
         $this->getClient()->beginTransaction();
 | 
| 
 | 
 | 
         try {
 | 
| 
 | 
 | 
             if($call($this->getClient(),...$params)){
 | 
| 
 | 
 | 
                 $this->getClient()->commit();
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
         }catch (\Throwable $e){
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 事务回滚
 | 
| 
 | 
 | 
      * @author:dc
 | 
| 
 | 
 | 
      * @time 2023/2/17 11:35
 | 
| 
 | 
 | 
      */
 | 
| 
 | 
 | 
     public function rollBack(){
 | 
| 
 | 
 | 
         $this->getClient()->rollBack();
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 事务提交
 | 
| 
 | 
 | 
      * 验证是否正常连接
 | 
| 
 | 
 | 
      * @return bool
 | 
| 
 | 
 | 
      * @author:dc
 | 
| 
 | 
 | 
      * @time 2023/2/17 11:35
 | 
| 
 | 
 | 
      * @time 2024/4/10 10:09
 | 
| 
 | 
 | 
      */
 | 
| 
 | 
 | 
     public function commit(){
 | 
| 
 | 
 | 
         $this->getClient()->commit();
 | 
| 
 | 
 | 
     public function ping(){
 | 
| 
 | 
 | 
         try {
 | 
| 
 | 
 | 
             $query = $this->getClient()->query("select 200;");
 | 
| 
 | 
 | 
             if($query->fetchColumn() == 200){
 | 
| 
 | 
 | 
                 return true;
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
         }catch (\Throwable $e){
 | 
| 
 | 
 | 
             return false;
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 //    /**
 | 
| 
 | 
 | 
 //     * 验证是否正常连接
 | 
| 
 | 
 | 
 //     * @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;
 | 
| 
 | 
 | 
 //    }
 | 
| 
 | 
 | 
         return false;
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 } | 
...
 | 
...
 | 
 |