diff --git a/library/think/db/driver.php b/library/think/db/driver.php index b07dfb8d..a1ff36a7 100644 --- a/library/think/db/driver.php +++ b/library/think/db/driver.php @@ -160,15 +160,21 @@ abstract class Driver { } } $this->bind = []; - $result = $this->PDOStatement->execute(); - // 调试结束 - $this->debug(false); - if ( false === $result ) { + try{ + $result = $this->PDOStatement->execute(); + // 调试结束 + $this->debug(false); + if ( false === $result ) { + $this->error(); + return false; + } else { + return $this->getResult(); + } + }catch (\PDOException $e) { $this->error(); return false; - } else { - return $this->getResult(); } + } /** @@ -207,18 +213,24 @@ abstract class Driver { } } $this->bind = []; - $result = $this->PDOStatement->execute(); - $this->debug(false); - if ( false === $result) { + try{ + $result = $this->PDOStatement->execute(); + $this->debug(false); + if ( false === $result) { + $this->error(); + return false; + } else { + $this->numRows = $this->PDOStatement->rowCount(); + if(preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) { + $this->lastInsID = $this->_linkID->lastInsertId(); + } + return $this->numRows; + } + }catch (\PDOException $e) { $this->error(); return false; - } else { - $this->numRows = $this->PDOStatement->rowCount(); - if(preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) { - $this->lastInsID = $this->_linkID->lastInsertId(); - } - return $this->numRows; } + } /**