modify
This commit is contained in:
+16
-7
@@ -168,7 +168,7 @@ class Command extends Component
|
|||||||
*/
|
*/
|
||||||
private function insert_or_change($isInsert, $hasAutoIncrement): bool|string|int
|
private function insert_or_change($isInsert, $hasAutoIncrement): bool|string|int
|
||||||
{
|
{
|
||||||
if (($result = $this->initPDOStatement()) === false) {
|
if (($result = $this->getPdoStatement()) === false) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
if ($isInsert === false) {
|
if ($isInsert === false) {
|
||||||
@@ -185,7 +185,7 @@ class Command extends Component
|
|||||||
* 重新构建
|
* 重新构建
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
private function initPDOStatement(): bool|int
|
private function getPdoStatement(): bool|int
|
||||||
{
|
{
|
||||||
if (empty($this->sql)) {
|
if (empty($this->sql)) {
|
||||||
return $this->addError('no sql.', 'mysql');
|
return $this->addError('no sql.', 'mysql');
|
||||||
@@ -193,16 +193,25 @@ class Command extends Component
|
|||||||
if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) {
|
if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) {
|
||||||
return $this->addError('get client error.', 'mysql');
|
return $this->addError('get client error.', 'mysql');
|
||||||
}
|
}
|
||||||
if (!(($this->prepare = $connect->prepare($this->sql)) instanceof PDOStatement)) {
|
if (!(($prepare = $connect->prepare($this->sql)) instanceof PDOStatement)) {
|
||||||
$error = $this->prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE;
|
return $this->addError($this->errorMessage($prepare), 'mysql');
|
||||||
|
|
||||||
return $this->addError($this->sql . ':' . $error, 'mysql');
|
|
||||||
}
|
}
|
||||||
$result = $this->checkResponse($this->prepare, $connect);
|
$result = $this->checkResponse($prepare, $connect);
|
||||||
|
$prepare->closeCursor();
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $prepare
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function errorMessage($prepare)
|
||||||
|
{
|
||||||
|
return $this->sql . ':' . ($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|\PDOStatement
|
* @return bool|\PDOStatement
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
|
|||||||
Reference in New Issue
Block a user