Doctrine\DBAL\Connection::lastInsertId PHP Method

lastInsertId() public method

Note: This method may not return a meaningful or consistent result across different drivers, because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY columns or sequences.
public lastInsertId ( string | null $seqName = null ) : string
$seqName string | null Name of the sequence object from which the ID should be returned.
return string A string representation of the last inserted ID.
    public function lastInsertId($seqName = null)
    {
        $this->connect();
        return $this->_conn->lastInsertId($seqName);
    }

Usage Example

 /**
  * @param string $tableName
  * @param array $rows
  */
 protected function insertTableRows($tableName, array $rows)
 {
     foreach ($rows as $rowKey => $values) {
         $this->connection->insert($tableName, $this->parser->parse($values));
         $this->parser->addReference($rowKey, $this->connection->lastInsertId());
     }
 }
All Usage Examples Of Doctrine\DBAL\Connection::lastInsertId