生成insert SQL
@access public

@param array $data    数据
@param array $options 表达式
@param bool  $replace 是否replace

@return string
@throws Exception
507581
public function insert(array $data, $options = [], $replace = false)
    {
        // 分析并处理数据
        $data = $this->parseData($data, $options);
        if (empty($data)) {
            return 0;
        }
        $fields = array_keys($data);
        $values = array_values($data);

        $sql = str_replace(
            ['%INSERT%', '%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'],
            [
                $replace ? 'REPLACE' : 'INSERT',
                $this->parseTable($options['table'], $options),
                implode(' , ', $fields),
                implode(' , ', $values),
                $this->parseComment($options['comment']),
            ], $this->insertSql);

        return $sql;
    }
39010
final public function insert(array $datas, bool $returning_id = false) {
      if (is_array($datas) && count($datas)) {
         if (!is_array(@$datas[0]))
            $datas = [$datas];

         $this->connection();
         $this->columns();

         $placeholders = [];
         $this->placeholder_data = [];

         foreach ($datas as $data) {
            $placeholder = [];
            foreach($this->columnsData as $column) {
               if(isset($data[$column])) {
                  $placeholder[$column] = "NULL";
                  if ( gettype($data[$column])==='boolean' )
                     $placeholder[$column] = $data[$column] ? 'TRUE' : 'FALSE';
                  elseif ( $data[$column]!=='' && $data[$column]!==NULL ) {
                     $placeholder[$column] = "?";
                     $this->placeholder_data[] = $data[$column];
                  }
               }
            }
            $placeholders[] = "(".implode(",", $placeholder).")";
         }

         $columns = "(".implode(",", array_keys($placeholder)).")";

         $placeholders = implode(",", $placeholders);


         $schema = '';
         $returning = '';
         if ($this->driver=='pgsql' && $this->schema) {
            if (!preg_match('/\./', $this->table)) {
               $schema = $this->schema ? $this->schema.'.' : '';	
            }
            $returning = $returning_id ? 'RETURNING '.$this->primaryKey : '';
         }

         $this->last_sql = $this->sql = "INSERT INTO {$schema}{$this->table} {$columns} VALUES {$placeholders} {$returning};";
         
         $this->fetch();

         $this->data = $this->rows;

         $this->reset();

         if ( $this->tableOrig!==NULL ) {
            $this->table = $this->tableOrig;
         }

         $error = $this->error();
         return $error['message'] ? FALSE : TRUE;
      }
      return FALSE;
   }
1184146
public static function create($data = [], $field = null, $replace = false)
    {
        $model = new static();

        if (!empty($field)) {
            $model->allowField($field);
        }

        $model->isUpdate(false)->replace($replace)->save($data, []);

        return $model;
    }
801468
public function insert($params, $ignore = false) {

		if(null === $this -> getAdapter()) {
			return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
		}

		if(false === is_array($params)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
		}

		if(0 === count($params)) {
			return trigger_error(sprintf('Argument 1 passed to %s() does not contain any value', __METHOD__), E_USER_ERROR);
		}

		if(false === is_bool($ignore)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($ignore)), E_USER_ERROR);
		}

		$query = [];

		if(true === $this -> is_multidimensional($params)) {

			$fields = 0;
			$escape	= [];
			$data 	= [];

			foreach($params as $index => $insert) {

				if(0 === $index) {
					$fields = $insert;
				}

				if(count($fields) !== count($insert)) {
					return trigger_error(sprintf('Amount of fields in array with index %s does not match the amount of fields in the first index (%s) in "%s"', $index, count($fields), __METHOD__), E_USER_ERROR);
				}

				$escape[] = sprintf('(%s)', implode(array_fill(0, count($insert), '?'), ','));
				$data = array_merge($data, array_values($insert));
			}

			$query[] = sprintf('INSERT%s INTO %s (%s)', (true === $ignore ? ' IGNORE' : ''), $this -> getAdapter() -> escape($this -> getTable()), $this -> getAdapter() -> escape(implode(array_keys($fields), ', ')));
			$query[] = sprintf('VALUES%s', implode($escape, ', '));
			$params  = $data;
		}
		else {
			
			$query[] = sprintf('INSERT%s INTO %s (%s)', (true === $ignore ? ' IGNORE' : ''), $this -> getAdapter() -> escape($this -> getTable()), $this -> getAdapter() -> escape(implode(array_keys($params), ', ')));
			$query[] = sprintf('VALUES(%s)', implode(array_fill(0, count($params), '?'), ','));
		}

		return $this -> getAdapter() -> query(implode(' ', $query), array_values($params)) -> execute();
	}
351649
public function insert($table, array $data)
    {
        $nameFields = join(',', array_keys($data));
        $preparedValues = $this->prepareValues($data);
        $keyValues = join(",", array_keys($preparedValues));
        $queryString = "INSERT INTO {$table} ({$nameFields}) VALUES ({$keyValues});";

        $this->query($queryString, $preparedValues);

        return $this->getInsertId();
    }
448966
public function buildInsertQuery($table, $data)
    {
        $sql = "INSERT INTO " . $this->quoteSpecialName($table) . " ";

        if (!empty($data['ON DUPLICATE'])) {
            $onDuplicate = $data['ON DUPLICATE'];
            unset($data['ON DUPLICATE']);
        }

        $keys = $values = '';

        foreach ($data as $key => $value) {
            if (!empty($keys)) $keys .= ', ';
            if (!empty($values)) $values .= ', ';

            $keys .= '`' . $key . '`';
            $values .= $this->escapeItem($value);
        }

        $keys = '(' . $keys . ')';
        $values = '(' . $values . ')';

        $sql .= $keys . ' VALUES ' . $values;

        if (!empty($onDuplicate)) {
            $sql .= " ON DUPLICATE KEY UPDATE " . $onDuplicate;
        }

        $sql .= ';';

        return $sql;
    }
906414
public function insert($table, array $data)
    {
        // Prepare
        $columnPart = "";
        $valuePart = "";

        // Loop the data
        foreach ($data as $column => $value) {
            $columnPart .= "`$column`, ";
            $valuePart .= "?, ";
        }

        // Remove last commas
        $columnPart = substr($columnPart, 0, -2);
        $valuePart = substr($valuePart, 0, -2);

        $query = "INSERT INTO `$table` ($columnPart) VALUES ($valuePart)";


        // Prepare and bind
        $statement = $this->prepare($query);

        $idx = 0;
        foreach ($data as $key => $value) {
            $statement->bindValue(($idx+1), $value, Database::typeOfValue($value));
            $idx++;
        }

        // Execute and return the execute returning value.
        return $statement->execute();
    }
932552
public function insert($collectionName, array $data, array $options = []) {
		$collection = $this->getCollection($collectionName);
		
		if ($this->_profilerEnabled) {
			$message = 'db.' . $collectionName . '.insert(' . json_encode($data) . ');';
			$event   = $this->getProfiler()->startInsert($message);
		}

		$result  = $collection->insert($data, $options);
		$success = (bool) $result['ok'];
		
		if ($this->_profilerEnabled) {
			$success
				? $event->stopSuccess()
				: $event->stopError();
		}
		
		return $success;
	}
399398
public function insert($data)
	{
		//var_dump($data);
		unset($this->_error);
		if(is_array($data))
		{
			$fields = '';
			$values = '';
			reset($data);
			for($counter = 0, $maxIndex = count($data), $valid = true; $counter < $maxIndex && $valid == true; $counter ++)
			{
				$elementKey = key($data);
				$elementKey = $this->_db->escape($elementKey);
				$valid = in_array($elementKey, $this->_fields);
				if($valid == true)
				{
                    $element = $data[$elementKey];
                    $element = $this->_db->escape($element);
					if(is_object($element) == true)
					{
						$valid = false;
						$this->_error = 'field: '.$elementKey.'is an object (this method just accept strings)';
					}
					else
					{
						if(is_numeric($element) == false)
							$values .= '\''.$element.'\'';
						else
							$values .= $element;
						$fields .= $elementKey;
						if(($counter + 1) < $maxIndex)
						{
							$fields .= ',';
							$values .= ',';
						}
						next($data);
					}
				}
				else
				{
					$this->_error = 'field: '.$elementKey.' is not defined in '.$this->_tableName;
				}
			}
			if($valid == true)
			{
				$this->_query = 'INSERT INTO '.$this->_tableName.'('.$fields.') VALUES('.$values.')';
				if($this->_db->execute($this->_query) !== false)
				{
					return $this->_db->insertId();
				}
				else
				{
					$this->_error = $this->_db->errorStr();
				}
			}
		}
		return false;
	}
505514
public static function replace(array $data)
    {
        if (empty($data)) {
            return false;
        }

        // Case where $data is not an array of arrays.
        if (!isset($data[0])) {
            $data = [$data];
        }

        $sql = static::buildReplaceSql($data);

        $data = static::inLineArray($data);

        return self::getModelConnectionName()->affectingStatement($sql, $data);
    }
688238
public static function insert($tname, $options=array()) {

        try {        
            return PdoLite::exec(self::qbInsert($tname, $options));
        } catch (PDOException $e) {
            die(self::dbError($tname));
        }
    }
453460
protected function buildInsertStatement($data) {
        $fields = '';
        $values = '';
        $first = true;
        foreach($data as $data_key => $data_val) {
            $fields .= ($first?'':',')."`$data_key`";
            $values .= ($first?'':',')."?";
            $first = false;
        }
        $table_name = $this->getTableName();
        return "INSERT INTO `{$table_name}` ({$fields}) VALUES ({$values})";
    }
41745
public function insert(array $data = array(), $update = false)
    {
        $this->viewCheck(__FUNCTION__);

        $data = array_merge($this->_schema['init'],
            array_filter($this->_schema['values'], array($this, 'filterRule')),
            array_filter($this->_schema['others'], array($this, 'filterRule')),
            $data);

        $params = array();
        foreach ($data as $key => $value)
            if (in_array($key, $this->_properties['primary_key']) && !$value)
                continue;
            elseif (is_array($value))
                return false;
            elseif (isset($this->_properties['fields'][$key]))
                $params[':'.$key] = $value;

        if (empty($params) || ($update && !$this->_properties['primary_key']))
            return false;

        $query = $this->buildInsert($params, $update);

        if (!($query && $this->validate($params)))
            return false;

        $old = clone $this;
        if (!$this->beforeInsert($params))
            return false;

        if ($result = $this->run($query, $params))
            $this->assign($params);

        if (!$this->afterInsert($old))
            return false;

        return $result;
    }
29984
public function update($query, $data, $option = array())
    {
        return $this->collection->update($query, $data, $option);
    }
703063
public function insert(array $data) {
        $statement = new InsertStatement($data);
        $statement->setStatementContext($this->statementContext);
        $sql = $statement->parse();

        $result = $this->connection->execute($sql, $this->statementContext->getParameters());

        $this->clear();

        if ($result === false) {
            return false;
        }

        return $this->connection->lastInsertId();
    }
787340
public function insert(array $data, $options = [])
    {
        // 分析并处理数据
        $data = $this->parseData($data, $options);
        $bulk = new BulkWrite;
        if ($insertId = $bulk->insert($data)) {
            $this->insertId = $insertId;
        }
        $this->log('insert', $data, $options);
        return $bulk;
    }
998182
public function insertRecord($table, array $data)
    {
        $dbHandle = $this->getDatabaseConnection();

        $fieldSet = array_keys($data);

        // Prepare sets
        $valueSet = array();
        foreach ($data as $key => $value) {
            $valueSet[':' . $key] = $value;
        }

        if (count($fieldSet) == 0 || count($valueSet) == 0) {
            throw new \Exception('Missing data for insert query', 1363894664);
        }

        $fieldSet[] = 'tstamp';
        $valueSet[':tstamp'] = time();

        $fieldSet[] = 'crdate';
        $valueSet[':crdate'] = time();

        $query = 'INSERT INTO ' . $table . ' (`' . implode('`,`', $fieldSet) . '`)
                  VALUES (' . implode(', ', array_keys($valueSet)) . ')';

        $statement = $dbHandle->prepare($query);
        $executeResult = $statement->execute($valueSet);

        $this->checkQueryError($statement, $executeResult, $valueSet);
        return $dbHandle->lastInsertId();
    }