src/Database/Model.php
public function insert(array $values) : int
    {
        $fields = $this->fields;
        array_shift($fields);

        $sql = 'INSERT INTO `' . $this->table . '` (' . implode(', ', $fields) . ') VALUES (:' . implode(', :', $fields) . ')';
        $query = $this->pdo->prepare($sql);
        foreach ($values as $key => &$value) {
            $query->bindParam(':' . $fields[$key], $value);
        }
        $query->execute();

        return $this->pdo->lastInsertId();
    }
public function insert(array $values) : int
    {
        $fields = $this->fields;
        array_shift($fields);

        $sql = 'INSERT INTO `' . $this->table . '` (' . implode(', ', $fields) . ') VALUES (:' . implode(', :', $fields) . ')';
        $query = $this->pdo->prepare($sql);
        foreach ($values as $key => &$value) {
            $query->bindParam(':' . $fields[$key], $value);
        }
        $query->execute();

        return $this->pdo->lastInsertId();
    }
public function insert ( array $ values ) : int { $ fields = $ this -> fields ; array_shift ( $ fields ) ; $ sql = 'INSERT INTO `' . $ this -> table . '` (' . implode ( ', ' , $ fields ) . ') VALUES (:' . implode ( ', :' , $ fields ) . ')' ; $ query = $ this -> pdo -> prepare ( $ sql ) ; foreach ( $ values as $ key => & $ value ) { $ query -> bindParam ( ':' . $ fields [ $ key ] , $ value ) ; } $ query -> execute ( ) ; return $ this -> pdo -> lastInsertId ( ) ; }
Insert a new record in the database
@param array $values Values to insert, except id, since it is expected to be AUTO_INCREMENT
@return int Return the last inserted id
@since 1.1.4
Insert a new record in the database