改进数据库驱动类的异常处理

This commit is contained in:
thinkphp
2015-05-07 11:58:47 +08:00
parent 33eed33826
commit 979b6a2d3e

View File

@@ -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;
}
}
/**