改进参数绑定机制 原生查询也可以支持参数绑定,并且同时支持 命名占位符和问号占位符 改进Driver类的异常处理 废除error方法

模型类中使用bind方法如下:
// 命名占位符
$this->bind('name','value');
// 问号占位符
$this->bind(1,'value');
This commit is contained in:
thinkphp
2016-01-21 17:37:10 +08:00
parent 0a323bc879
commit c3412cfb12
4 changed files with 125 additions and 149 deletions

View File

@@ -11,6 +11,7 @@
namespace think\db\driver;
use think\Db;
use think\db\Driver;
/**
@@ -64,30 +65,20 @@ class Oracle extends Driver
$this->free();
}
$this->executeTimes++;
// 记录开始执行时间
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if (false === $this->PDOStatement) {
$this->error();
return false;
}
Db::$executeTimes++;
try {
$result = $this->PDOStatement->execute($bind);
// 记录开始执行时间
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
$result = $this->PDOStatement->execute($bind);
$this->debug(false);
if (false === $result) {
$this->error();
return false;
} else {
$this->numRows = $this->PDOStatement->rowCount();
if ($flag || preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
$this->lastInsID = $this->_linkID->lastInsertId();
}
return $this->numRows;
$this->numRows = $this->PDOStatement->rowCount();
if ($flag || 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;
throw new Exception($e->getMessage());
}
}