The difference between add and addAll
The sql statement key and value generated by the add operation correspond one-to-one, but sometimes the sql statement key and value generated by addAll do not correspond one-to-one
reason
1.Add the class that generates sql is Driver, in the loop fields and $values maintain a one-to-one correspondence
foreach ($data as $key=>$val){
if(is_array($val) && 'exp' == $val[0]){
$fields[] = $this->parseKey($key);
$values[] = $val[1];
}elseif(is_null($val)){
$fields[] = $this->parseKey($key);
$values[] = 'NULL';
}elseif(is_scalar($val)) { // 过滤非标量数据
$fields[] = $this->parseKey($key);
if(0===strpos($val,':') && in_array($val,array_keys($this->bind))){
$values[] = $this->parseValue($val);
}else{
$name = count($this->bind);
$values[] = ':'.$name;
$this->bindParam($name,$val);
}
}
2. The class of addAll to generate sql is Mysql, first generate
data, this is when $val is
illegal, the value will be lost, resulting in a mismatch
$fields = array_map(array($this,'parseKey'),array_keys($dataSet[0])); //先生成$fields数组
foreach ($dataSet as $data){
$value = array();
foreach ($data as $key=>$val){
if(is_array($val) && 'exp' == $val[0]){
$value[] = $val[1];
}elseif(is_scalar($val) || is_null($val)){
if(0===strpos($val,':') && in_array($val,array_keys($this->bind))){
$value[] = $this->parseValue($val);
}else{
$name = count($this->bind);
$value[] = ':'.$name;
$this->bindParam($name,$val);
}
}
}
$values[] = '('.implode(',', $value).')';
}