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

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 = []; $this->bind = [];
$result = $this->PDOStatement->execute(); try{
// 调试结束 $result = $this->PDOStatement->execute();
$this->debug(false); // 调试结束
if ( false === $result ) { $this->debug(false);
if ( false === $result ) {
$this->error();
return false;
} else {
return $this->getResult();
}
}catch (\PDOException $e) {
$this->error(); $this->error();
return false; return false;
} else {
return $this->getResult();
} }
} }
/** /**
@@ -207,18 +213,24 @@ abstract class Driver {
} }
} }
$this->bind = []; $this->bind = [];
$result = $this->PDOStatement->execute(); try{
$this->debug(false); $result = $this->PDOStatement->execute();
if ( false === $result) { $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(); $this->error();
return false; 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;
} }
} }
/** /**