Bluz\Db\Table::insert PHP Метод

insert() публичный статический Метод

Table::insert(['login' => 'Man', 'email' => '[email protected]'])
public static insert ( array $data ) : string | null
$data array Column-value pairs
Результат string | null Primary key or null
    public static function insert(array $data)
    {
        $self = static::getInstance();
        $data = $self->filterColumns($data);
        if (!sizeof($data)) {
            throw new DbException("Invalid field names of table `{$self->table}`. Please check use of `insert()` method");
        }
        $table = DbProxy::quoteIdentifier($self->table);
        $sql = "INSERT INTO {$table} SET " . join(',', self::prepareStatement($data));
        $result = DbProxy::query($sql, array_values($data));
        if (!$result) {
            return null;
        }
        /**
         * If a sequence name was not specified for the name parameter, PDO::lastInsertId()
         * returns a string representing the row ID of the last row that was inserted into the database.
         *
         * If a sequence name was specified for the name parameter, PDO::lastInsertId()
         * returns a string representing the last value retrieved from the specified sequence object.
         *
         * If the PDO driver does not support this capability, PDO::lastInsertId() triggers an IM001 SQLSTATE.
         */
        return DbProxy::handler()->lastInsertId($self->sequence);
    }