src/DB/Drivers/PDOSqlDriver.php
public function add($table, $data, $multi = false, &$insert_data = array(), $openTA = false)
    {
        $this->SQLAssembler->add($table, $data, $multi);
        $this->sql = $this->SQLAssembler->getSQL();
        $this->params = $this->SQLAssembler->getParams();

        if ($multi) {
            $add_count = 0;
            if (!empty($this->params)) {
                $inc_name = $this->getAutoIncrementName($table);
                $stmt = $this->prepare($this->sql);

                if ($openTA) {
                    $this->beginTA();
                    try {
                        if (!empty($this->params)) {
                            foreach ($this->params as $p) {
                                if ($stmt->exec($p, true)) {
                                    $add_data_info = array_combine($data['fields'], $p);
                                    if ($inc_name) {
                                        $add_data_info[$inc_name] = $this->insertId();
                                    }

                                    $add_count++;
                                    $insert_data[] = $add_data_info;
                                }
                            }
                        }
                    } catch (Exception $e) {
                        $insert_data = array();
                        $this->rollBack();
                        throw new CoreException($e->getMessage());
                    }
                    $this->commit();
                } else {
                    if (!empty($this->params)) {
                        foreach ($this->params as $p) {
                            if ($stmt->exec($p, true)) {
                                $add_data_info = array_combine($data['fields'], $p);
                                if ($inc_name) {
                                    $add_data_info[$inc_name] = $this->insertId();
                                }

                                $add_count++;
                                $insert_data[] = $add_data_info;
                            }
                        }
                    }
                }
            }
            return $add_count;
        } else {
            $add_count = $this->prepare($this->sql)->exec($this->params, true);
            $last_insert_id = $this->insertId();
            if ($last_insert_id > 0) {
                return $last_insert_id;
            }

            return $add_count;
        }
    }
public function add($table, $data, $multi = false, &$insert_data = array(), $openTA = false)
    {
        $this->SQLAssembler->add($table, $data, $multi);
        $this->sql = $this->SQLAssembler->getSQL();
        $this->params = $this->SQLAssembler->getParams();

        if ($multi) {
            $add_count = 0;
            if (!empty($this->params)) {
                $inc_name = $this->getAutoIncrementName($table);
                $stmt = $this->prepare($this->sql);

                if ($openTA) {
                    $this->beginTA();
                    try {
                        if (!empty($this->params)) {
                            foreach ($this->params as $p) {
                                if ($stmt->exec($p, true)) {
                                    $add_data_info = array_combine($data['fields'], $p);
                                    if ($inc_name) {
                                        $add_data_info[$inc_name] = $this->insertId();
                                    }

                                    $add_count++;
                                    $insert_data[] = $add_data_info;
                                }
                            }
                        }
                    } catch (Exception $e) {
                        $insert_data = array();
                        $this->rollBack();
                        throw new CoreException($e->getMessage());
                    }
                    $this->commit();
                } else {
                    if (!empty($this->params)) {
                        foreach ($this->params as $p) {
                            if ($stmt->exec($p, true)) {
                                $add_data_info = array_combine($data['fields'], $p);
                                if ($inc_name) {
                                    $add_data_info[$inc_name] = $this->insertId();
                                }

                                $add_count++;
                                $insert_data[] = $add_data_info;
                            }
                        }
                    }
                }
            }
            return $add_count;
        } else {
            $add_count = $this->prepare($this->sql)->exec($this->params, true);
            $last_insert_id = $this->insertId();
            if ($last_insert_id > 0) {
                return $last_insert_id;
            }

            return $add_count;
        }
    }
插入数据

@see SQLAssembler::add()
@param string $table
@param string|array $data
@param bool $multi 是否批量添加
@param array $insert_data 批量添加的数据
@param bool $openTA 批量添加时是否开启事务
@return bool|mixed
@throws CoreException