eee
This commit is contained in:
+4
-2
@@ -109,6 +109,7 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
$client = $this->connection->getConnection();
|
$client = $this->connection->getConnection();
|
||||||
try {
|
try {
|
||||||
|
$startTime = microtime(true);
|
||||||
if (($prepare = $client->prepare($this->sql)) === false) {
|
if (($prepare = $client->prepare($this->sql)) === false) {
|
||||||
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $client->errorInfo()[2]);
|
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $client->errorInfo()[2]);
|
||||||
}
|
}
|
||||||
@@ -118,7 +119,7 @@ class Command extends Component
|
|||||||
$result = $method == 'rowCount' ? $prepare->rowCount() : $prepare->{$method}(PDO::FETCH_ASSOC);
|
$result = $method == 'rowCount' ? $prepare->rowCount() : $prepare->{$method}(PDO::FETCH_ASSOC);
|
||||||
$prepare->closeCursor();
|
$prepare->closeCursor();
|
||||||
|
|
||||||
$this->connection->println($this->sql, $this->params);
|
$this->connection->println($startTime, microtime(true), $this->sql, $this->params);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
@@ -151,6 +152,7 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
$client = $this->connection->getConnection();
|
$client = $this->connection->getConnection();
|
||||||
try {
|
try {
|
||||||
|
$startTime = microtime(true);
|
||||||
if (($prepare = $client->prepare($this->sql)) === false) {
|
if (($prepare = $client->prepare($this->sql)) === false) {
|
||||||
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $prepare->errorInfo()[2]);
|
throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $prepare->errorInfo()[2]);
|
||||||
}
|
}
|
||||||
@@ -161,7 +163,7 @@ class Command extends Component
|
|||||||
|
|
||||||
$result = $client->lastInsertId();
|
$result = $client->lastInsertId();
|
||||||
|
|
||||||
$this->connection->println($this->sql, $this->params);
|
$this->connection->println($startTime, microtime(true), $this->sql, $this->params);
|
||||||
|
|
||||||
return $result == 0 ? $prepare->rowCount() : (int)$result;
|
return $result == 0 ? $prepare->rowCount() : (int)$result;
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
|
|||||||
+12
-10
@@ -79,14 +79,16 @@ class Connection extends Component
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param float $startTime
|
||||||
|
* @param float $endTime
|
||||||
* @param string $sql
|
* @param string $sql
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function println(string $sql, array $params = []): void
|
public function println(float $startTime, float $endTime, string $sql, array $params = []): void
|
||||||
{
|
{
|
||||||
if (is_callable($this->_println)) {
|
if (is_callable($this->_println)) {
|
||||||
call_user_func($this->_println, $sql, $params);
|
call_user_func($this->_println, $startTime, $endTime, $sql, $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +115,7 @@ class Connection extends Component
|
|||||||
*/
|
*/
|
||||||
public function tick(): void
|
public function tick(): void
|
||||||
{
|
{
|
||||||
$this->timerId = Timer::tick($this->tick_time, fn() => $this->checkClientHealth($this->pool()));
|
$this->timerId = Timer::tick($this->tick_time, fn () => $this->checkClientHealth($this->pool()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -349,13 +351,13 @@ class Connection extends Component
|
|||||||
{
|
{
|
||||||
$pdo = new PDO($this->database, $this->cds, $this->username, $this->password, [
|
$pdo = new PDO($this->database, $this->cds, $this->username, $this->password, [
|
||||||
// $pdo = new \PDO('mysql:dbname=' . $this->database . ';host=' . $this->cds, $this->username, $this->password, [
|
// $pdo = new \PDO('mysql:dbname=' . $this->database . ';host=' . $this->cds, $this->username, $this->password, [
|
||||||
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||||
\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
|
\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
|
||||||
\PDO::ATTR_STRINGIFY_FETCHES => false,
|
\PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||||
\PDO::ATTR_EMULATE_PREPARES => true,
|
\PDO::ATTR_EMULATE_PREPARES => true,
|
||||||
\PDO::ATTR_TIMEOUT => $this->timeout,
|
\PDO::ATTR_TIMEOUT => $this->timeout,
|
||||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
||||||
]);
|
]);
|
||||||
foreach ($this->attributes as $key => $attribute) {
|
foreach ($this->attributes as $key => $attribute) {
|
||||||
$pdo->setAttribute($key, $attribute);
|
$pdo->setAttribute($key, $attribute);
|
||||||
|
|||||||
Reference in New Issue
Block a user