src/main/php/DataDo/Data/Repository.php
public function insert($entity)
    {
        $values = $this->getInsertValues($entity, $this->namingContention);
        $keyString = implode(array_keys($values), ', ');
        $questionMarkString = count($values) === 0 ? '' : ('?' . str_repeat(', ?', count($values) - 1));

        $sql = "INSERT INTO $this->tableName ($keyString) VALUES ($questionMarkString)";
        $sth = $this->pdo->prepare($sql);
        $sth->execute(array_values($values));
        $id = $this->pdo->lastInsertId();

        if ($this->idProperty !== null) {
            $this->idProperty->setValue($entity, $id);
        }

        return $id;
    }
public function insert($entity)
    {
        $values = $this->getInsertValues($entity, $this->namingContention);
        $keyString = implode(array_keys($values), ', ');
        $questionMarkString = count($values) === 0 ? '' : ('?' . str_repeat(', ?', count($values) - 1));

        $sql = "INSERT INTO $this->tableName ($keyString) VALUES ($questionMarkString)";
        $sth = $this->pdo->prepare($sql);
        $sth->execute(array_values($values));
        $id = $this->pdo->lastInsertId();

        if ($this->idProperty !== null) {
            $this->idProperty->setValue($entity, $id);
        }

        return $id;
    }
public function insert ( $ entity ) { $ values = $ this -> getInsertValues ( $ entity , $ this -> namingContention ) ; $ keyString = implode ( array_keys ( $ values ) , ', ' ) ; $ questionMarkString = count ( $ values ) === 0 ? '' : ( '?' . str_repeat ( ', ?' , count ( $ values ) - 1 ) ) ; $ sql = "INSERT INTO $this->tableName ($keyString) VALUES ($questionMarkString)" ; $ sth = $ this -> pdo -> prepare ( $ sql ) ; $ sth -> execute ( array_values ( $ values ) ) ; $ id = $ this -> pdo -> lastInsertId ( ) ; if ( $ this -> idProperty !== null ) { $ this -> idProperty -> setValue ( $ entity , $ id ) ; } return $ id ; }
Insert an entity into the database.
You can optionally provide a property name. If you do the inserted id will be assigned to that property.
@param $entity
@return integer the id of the row that was inserted
Insert an entity into the database . You can optionally provide a property name . If you do the inserted id will be assigned to that property .