参数绑定改用bindParam方法实现 可以支持参数类型

This commit is contained in:
ThinkPHP
2013-04-27 17:10:03 +08:00
parent 8a516c5242
commit 7070eee979

View File

@@ -142,7 +142,15 @@ abstract class Driver {
$this->PDOStatement = $this->_linkID->prepare($str); $this->PDOStatement = $this->_linkID->prepare($str);
if(false === $this->PDOStatement) if(false === $this->PDOStatement)
E($this->error()); E($this->error());
$result = $this->PDOStatement->execute($bind); foreach ($bind as $key => $val) {
if(is_array($val)){
$this->PDOStatement->bindParam($key, $val[0], $val[1]);
}else{
$this->PDOStatement->bindParam($key, $val);
}
}
$result = $this->PDOStatement->execute();
//$result = $this->PDOStatement->execute($bind);
// 调试结束 // 调试结束
$this->debug(false); $this->debug(false);
if ( false === $result ) { if ( false === $result ) {
@@ -176,7 +184,14 @@ abstract class Driver {
if(false === $this->PDOStatement) { if(false === $this->PDOStatement) {
E($this->error()); E($this->error());
} }
$result = $this->PDOStatement->execute($bind); foreach ($bind as $key => $val) {
if(is_array($val)){
$this->PDOStatement->bindParam($key, $val[0], $val[1]);
}else{
$this->PDOStatement->bindParam($key, $val);
}
}
$result = $this->PDOStatement->execute();
$this->debug(false); $this->debug(false);
if ( false === $result) { if ( false === $result) {
$this->error(); $this->error();
@@ -184,21 +199,12 @@ abstract class Driver {
} else { } else {
$this->numRows = $this->PDOStatement->rowCount(); $this->numRows = $this->PDOStatement->rowCount();
if(preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) { if(preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
$this->lastInsID = $this->getLastInsertId(); $this->lastInsID = $this->_linkID->lastInsertId();
} }
return $this->numRows; return $this->numRows;
} }
} }
/**
* 获取最后插入id
* @access public
* @return integer
*/
public function getLastInsertId() {
return $this->_linkID->lastInsertId();
}
/** /**
* 启动事务 * 启动事务
* @access public * @access public
@@ -304,8 +310,13 @@ abstract class Driver {
if('' != $this->queryStr){ if('' != $this->queryStr){
$this->error .= "\n [ SQL语句 ] : ".$this->queryStr; $this->error .= "\n [ SQL语句 ] : ".$this->queryStr;
} }
// 记录错误日志
Log::record($this->error,'ERR'); Log::record($this->error,'ERR');
return $this->error; if($this->config['debug']) {// 开启数据库调试模式
E($this->error);
}else{
return $this->error;
}
} }
/** /**