db_mysqli::insertAll PHP Method

insertAll() public method

插入记录
public insertAll ( mixed $datas, array $options = [], boolean $replace = false ) : false | integer
$datas mixed 数据
$options array 参数表达式
$replace boolean 是否replace
return false | integer | integer
    public function insertAll($datas, $options = array(), $replace = false)
    {
        if (!is_array(reset($datas))) {
            return false;
        }
        $fields = array_keys($datas[0]);
        array_walk($fields, array($this, 'parseKey'));
        $values = array();
        foreach ($datas as $data) {
            $value = array();
            foreach ($data as $key => $val) {
                $val = $this->parseValue($val);
                if (is_scalar($val)) {
                    // 过滤非标量数据
                    $value[] = $val;
                }
            }
            $values[] = '(' . implode(',', $value) . ')';
        }
        $sql = ($replace ? 'REPLACE' : 'INSERT') . ' INTO ' . $this->parseTable($options['table']) . ' (' . implode(',', $fields) . ') VALUES ' . implode(',', $values);
        return $this->execute($sql);
    }