yii\db\Schema::insert PHP Method

insert() public method

Executes the INSERT command, returning primary key values.
Since: 2.0.4
public insert ( string $table, array $columns ) : array | false
$table string the table that new rows will be inserted into.
$columns array the column data (name => value) to be inserted into the table.
return array | false primary key values or false if the command fails
    public function insert($table, $columns)
    {
        $command = $this->db->createCommand()->insert($table, $columns);
        if (!$command->execute()) {
            return false;
        }
        $tableSchema = $this->getTableSchema($table);
        $result = [];
        foreach ($tableSchema->primaryKey as $name) {
            if ($tableSchema->columns[$name]->autoIncrement) {
                $result[$name] = $this->getLastInsertID($tableSchema->sequenceName);
                break;
            } else {
                $result[$name] = isset($columns[$name]) ? $columns[$name] : $tableSchema->columns[$name]->defaultValue;
            }
        }
        return $result;
    }