This commit is contained in:
2020-09-06 04:44:13 +08:00
parent a0bb92f0a7
commit 865e126fcc
+26 -24
View File
@@ -41,24 +41,6 @@ class Command extends Component
/** @var PDOStatement */ /** @var PDOStatement */
private $prepare; private $prepare;
/**
* 重新构建
* @throws
*/
private function initPDOStatement()
{
if (empty($this->sql)) {
return null;
}
if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) {
return null;
}
$this->prepare = $connect->prepare($this->sql);
if (!($this->prepare instanceof PDOStatement)) {
return $this->addError($this->sql . ':' . $this->getError());
}
return $this->prepare;
}
/** /**
* @return bool|PDOStatement * @return bool|PDOStatement
@@ -255,23 +237,43 @@ class Command extends Component
*/ */
private function insert_or_change($isInsert, $hasAutoIncrement) private function insert_or_change($isInsert, $hasAutoIncrement)
{ {
if (!$this->initPDOStatement()) { if (!($connection = $this->initPDOStatement())) {
return false; return false;
} }
$this->bind($this->prepare); if (($result = $this->prepare->execute($this->prepare)) === false) {
if (($result = $this->prepare->execute()) === false) { return $this->addError($connection->errorInfo()[2]);
return $this->addErrorLog();
} }
if (!$isInsert) { if (!$isInsert) {
return true; return true;
} }
$result = $this->connection->lastInsertId(); $result = $connection->lastInsertId();
if ($result == 0 && $hasAutoIncrement) { if ($result == 0 && $hasAutoIncrement) {
return $this->addErrorLog(); return $this->addError($connection->errorInfo()[2]);
} }
return $result; return $result;
} }
/**
* 重新构建
* @throws
*/
private function initPDOStatement()
{
if (empty($this->sql)) {
return null;
}
if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) {
return null;
}
$this->prepare = $connect->prepare($this->sql);
if (!($this->prepare instanceof PDOStatement)) {
return $this->addError($this->sql . ':' . $this->getError());
}
return $connect;
}
/** /**
* @param $modelName * @param $modelName
* @return $this * @return $this