The difference between thinkphp3.2 add and addAll

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 d a t a Time 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 f i e l d s exist follow ring 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).')';
        }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325988592&siteId=291194637