Think/Db/Driver类改进自动参数绑定的处理

This commit is contained in:
ThinkPHP
2013-04-26 21:40:26 +08:00
parent 8365c5d7cd
commit b54ee372f5

View File

@@ -327,9 +327,13 @@ abstract class Driver {
foreach ($data as $key=>$val){ foreach ($data as $key=>$val){
$value = $this->parseValue($val); $value = $this->parseValue($val);
if(is_scalar($value)) {// 过滤非标量数据 if(is_scalar($value)) {// 过滤非标量数据
$name = md5($key); if(0===strpos($value,':')){
$set[] = $this->parseKey($key).'=:T'.$name; $set[] = $this->parseKey($key).'='.$value;
$this->bindParam($name,$value); }else{
$name = md5($key);
$set[] = $this->parseKey($key).'=:T'.$name;
$this->bindParam($name,$value);
}
} }
} }
return ' SET '.implode(',',$set); return ' SET '.implode(',',$set);
@@ -740,9 +744,13 @@ abstract class Driver {
$value = $this->parseValue($val); $value = $this->parseValue($val);
if(is_scalar($value)) { // 过滤非标量数据 if(is_scalar($value)) { // 过滤非标量数据
$fields[] = $this->parseKey($key); $fields[] = $this->parseKey($key);
$name = md5($key); if(0===strpos($value,':')){
$values[] = ':'.$name; $values[] = $value;
$this->bindParam($name,$value); }else{
$name = md5($key);
$values[] = ':T'.$name;
$this->bindParam($name,$value);
}
} }
} }
$sql = ($replace?'REPLACE':'INSERT').' INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES ('.implode(',', $values).')'; $sql = ($replace?'REPLACE':'INSERT').' INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES ('.implode(',', $values).')';