...
|
...
|
@@ -28,12 +28,24 @@ class DbPool { |
|
|
* @time 2023/2/13 9:12
|
|
|
*/
|
|
|
public function getClient(){
|
|
|
if(!$this->client){
|
|
|
$this->connect();
|
|
|
}
|
|
|
return $this->client;
|
|
|
}
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->connect();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 连接sql
|
|
|
* @author:dc
|
|
|
* @time 2023/3/23 9:14
|
|
|
*/
|
|
|
public function connect(){
|
|
|
try {
|
|
|
$this->client = new \PDO(
|
|
|
'mysql:charset=utf8mb4;dbname='.DB_DATABASE.';host='.DB_HOST.';port='.DB_PORT,
|
...
|
...
|
@@ -46,9 +58,8 @@ class DbPool { |
|
|
]
|
|
|
);
|
|
|
}catch (\PDOException $e){
|
|
|
|
|
|
logs($e->getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -70,7 +81,7 @@ class DbPool { |
|
|
$timer = microtime(true);
|
|
|
}
|
|
|
|
|
|
$query = $this->client->prepare($sql);
|
|
|
$query = $this->getClient()->prepare($sql);
|
|
|
|
|
|
$ret = $query->execute($params);
|
|
|
|
...
|
...
|
@@ -165,7 +176,7 @@ class DbPool { |
|
|
$query = $this->query([$sql,$data]);
|
|
|
|
|
|
if($query){
|
|
|
return $this->client->lastInsertId();
|
|
|
return $this->getClient()->lastInsertId();
|
|
|
}
|
|
|
|
|
|
return 0;
|
...
|
...
|
@@ -266,7 +277,7 @@ class DbPool { |
|
|
* @time 2023/2/17 11:35
|
|
|
*/
|
|
|
public function transaction(){
|
|
|
$this->client->beginTransaction();
|
|
|
$this->getClient()->beginTransaction();
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -275,7 +286,7 @@ class DbPool { |
|
|
* @time 2023/2/17 11:35
|
|
|
*/
|
|
|
public function rollBack(){
|
|
|
$this->client->rollBack();
|
|
|
$this->getClient()->rollBack();
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -284,7 +295,7 @@ class DbPool { |
|
|
* @time 2023/2/17 11:35
|
|
|
*/
|
|
|
public function commit(){
|
|
|
$this->client->commit();
|
|
|
$this->getClient()->commit();
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|