Inserts a table row with specified data.

@param mixed $table The table to insert data into.
@param array $bind Column-value pairs.
@return int The number of affected rows.
326577
function insertSql($table, array $bind)
    {
        // extract and quote col names from the array keys
        $cols = array();
        $vals = array();
        $this->extractAndQuoteCols($bind, $cols, $vals);
        // build the statement
        $sql = "INSERT INTO "
            . $this->wrappedAdapter->quoteIdentifier($table, true)
            . ' (' . implode(', ', $cols) . ') '
            . 'VALUES (' . implode(', ', $vals) . ')';
        return $sql;
    }
237512
public function insert($table, $row)
    {
        if (!array_key_exists($table, $this->rows)) {
            $this->loadTable($table);
        }

        $data = $this->sanitiseRow($table, $row);

        $this->rows[$table][] = $data;
    }
205984
protected function bindValue(array $bind = [])
    {
        foreach ($bind as $key => $val) {
            // 占位符
            $param = is_numeric($key) ? $key + 1 : ':' . $key;

            if (is_array($val)) {
                if (PDO::PARAM_INT == $val[1] && '' === $val[0]) {
                    $val[0] = 0;
                } elseif (self::PARAM_FLOAT == $val[1]) {
                    $val[0] = (float) $val[0];
                    $val[1] = PDO::PARAM_STR;
                }

                $result = $this->PDOStatement->bindValue($param, $val[0], $val[1]);
            } else {
                $result = $this->PDOStatement->bindValue($param, $val);
            }

            if (!$result) {
                throw new BindParamException(
                    "Error occurred  when binding parameters '{$param}'",
                    $this->config,
                    $this->getLastsql(),
                    $bind
                );
            }
        }
    }
1248906
public function insert($table, $values)
    {
        if ( !is_array(reset($values)) ) { // is this an array of arrays? if not lets make it one
            $values = [$values];
        }

        $keys = array_keys(reset($values));
        $keynames = "`" . implode("`,`",$keys) . "`";

        $qvals = $allvars = [];
        foreach( $values as $pos => $subval ) {
            if ( array_keys($subval) != $keys ) {
                throw new \Exception("Value set at position $pos has non-matching keys!!");
            }
            $questionmarks = [];
            foreach ( $subval as $value ) {
                $allvars[] = $value;
                $questionmarks[] = "?";
            }
            $qvals[] = "(" . implode(",", $questionmarks) . ")";
        }

        $qvstring = implode( ",", $qvals );
        $query = "INSERT INTO `$table` ($keynames) VALUES $qvstring";

        return $this->query( $query, $allvars );
    }
103933
public static function insert($table, array $set)
	{
		$query = 'INSERT INTO ' . self::escapeTableName($table) . ' SET ';
		$values = array ();
		foreach ($set as $k => $v) {
			$query .= $k . ' = ?, ';

			// No array? Then it's a simple string.
			if (is_array ($v)) {
				$values[] = $v;
			} else {
				$values[] = array($v);
			}
		}

		$query = substr($query, 0, -2);

		$query = new self($query);
		$query->bindValues($values);

		return $query;
	}
599397
public function insertRow($table, array $settings, $bind = true)
    {
        //argument test
        Argument::i()
            //Argument 1 must be a string
            ->test(1, 'string')
            //Argument 3 must be an array or bool
            ->test(3, 'array', 'bool');
        
        //build insert query
        $query = $this->insert($table);
        
        //foreach settings
        foreach ($settings as $key => $value) {
            //if value is not a vulnerability
            if (is_null($value) || is_bool($value)) {
                //just add it to the query
                $query->set($key, $value);
                continue;
            }
            
            //if bind is true or is an array and we want to bind it
            if ($bind === true || (is_array($bind) && in_array($key, $bind))) {
                //bind the value
                $value = $this->bind($value);
            }
            
            //add it to the query
            $query->set($key, $value);
        }
        
        //run the query
        $this->query($query, $this->getBinds());
        
        //event trigger
        $this->trigger('sql-insert', $table, $settings);
        
        return $this;
    }
349250
protected function bindParam($bind)
    {
        foreach ($bind as $key => $val) {
            $param = is_numeric($key) ? $key + 1 : ':' . $key;

            if (is_array($val)) {
                array_unshift($val, $param);
                $result = call_user_func_array([$this->PDOStatement, 'bindParam'], $val);
            } else {
                $result = $this->PDOStatement->bindValue($param, $val);
            }

            if (!$result) {
                $param = array_shift($val);

                throw new BindParamException(
                    "Error occurred  when binding parameters '{$param}'",
                    $this->config,
                    $this->getLastsql(),
                    $bind
                );
            }
        }
    }
719676
public function update($table, array $data, $where = [], array $bind = [])
    {
        $table  = $this->quote()->identifier($table);
        $fields = [];
        foreach ($data as $field => $value) {
            $fields[] = $this->quote()->into("{$field} = ?", $value);
        }
        $sql = "UPDATE $table SET " . implode(', ', $fields);
        if (is_array($where)) {
            $where = $this->createWhereExpression($where);
        }
        $sql .= (($where) ? " WHERE {$where}" : '');

        $stmt = $this->query($sql, $bind);

        return $stmt->rowCount();
    }
60876
public static function insert($table, $data = array(), $config = array()) {
        DB::connect();
        return DB::$connection->insert($table, $data, $config);
    }
1115659
public function updateRows(string $table, array $set, array $where): int
    {
        $update = new Update($this->options);
        $sqlParams = $update->buildQuery($table, $set, $where);
        return $this->query($sqlParams->getSql(), $sqlParams->getParams())->getAffected();
    }
549522
public function insert($table, $params) {
		$params = $this->filter_table_data($table, $params, $this);

		$keys = array_keys($params);
		foreach ($keys as $key => $value) {
			$keys[$key] = $this->quote_identifier($value);
		}

		$query = 'INSERT INTO ' . $this->quote_identifier($table) . ' (' . implode(',', $keys) . ') VALUES (';

		for ($i=0; $i < count($params); $i++) {
			if ($i > 0) {
				$query .= ', ';
			}
			$query .= '?';
		}

		$query .= ') ';
		$statement = $this->get_statement($query, $params);
		$statement->execute();
	}
206304
public function insert($table, $row)
	{
		$keys = implode('`, `', array_keys($row));
        $holds = implode(',', array_fill(0, count($row), '?'));
		$vals = array_values($row);

		$sql = "INSERT INTO `{$table}` (`{$keys}`) VALUES({$holds})";

        $stmt = $this->prepare($sql);
        return $stmt ? $stmt->execute($vals) : false;
	}
353511
protected function bindValue(array $bind = []) {
        foreach ($bind as $key => $val) {
            // 占位符
            $param = is_numeric($key) ? $key + 1 : ':' . $key;
            if (is_array($val)) {
                if (PDO::PARAM_INT == $val[ 1 ] && '' === $val[ 0 ]) {
                    $val[ 0 ] = 0;
                }
                $this->PDOStatement->bindValue($param, $val[ 0 ], $val[ 1 ]);
            } else {
                $this->PDOStatement->bindValue($param, $val);
            }
        }
    }
899483
public function insert(Table $table, $row)
    {
        $end = $this->startCommandTimer();
        $this->writeCommand('insert', [$table->getName()]);
        parent::insert($table, $row);
        $end();
    }
1290333
private function insertRow($tableName, Connection $connection, array $data, Closure $getColumnType): void
    {
        $types        = [];
        $quotedFields = [];
        foreach ($data as $column => $value) {
            $name                = $connection->quoteIdentifier($column);
            $quotedFields[$name] = $value;
            $types[$name]        = $getColumnType($column);
        }

        try {
            $result = $connection->insert($tableName, $quotedFields, $types);
            assert($result !== false, 'Insert failed');
        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (UniqueConstraintViolationException $e) {
            // ignore non-unique records
        }
    }
631714
public function execute($sql, $bind = [], $has_insert_id = false)
    {
        $sql = $this->_replaceQuoteCharacters($sql);

        try {
            $r = $bind ? $this->_execute($sql, $bind)->rowCount() : @$this->_getPdo()->exec($sql);
            if ($has_insert_id) {
                return $this->_getPdo()->lastInsertId();
            } else {
                return $r;
            }
        } catch (\PDOException $e) {
            throw new DbException([
                ':message => ' . PHP_EOL . 'SQL: ":sql"' . PHP_EOL . ' BIND: :bind',
                'message' => $e->getMessage(),
                'sql' => $sql,
                'bind' => json_encode($bind, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
            ]);
        }
    }
529384
public function set($table, $data, $tablePrefix = null)
    {
        if (is_array($data)) {
            is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;

            $bulk = new BulkWrite();
            $insertId = $bulk->insert($data);
            $result = $this->runMongoBulkWrite($tablePrefix . $table, $bulk);

            Cml::$debug && $this->debugLogSql('BulkWrite INSERT', $tablePrefix . $table, [], $data);

            if ($result->getInsertedCount() > 0) {
                $this->lastInsertId = sprintf('%s', $insertId);
            }
            return $this->insertId();
        } else {
            return false;
        }
    }