Zend_Db_Adapter_Pdo_Abstract::lastInsertId PHP Method

lastInsertId() public method

As a convention, on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence from the arguments and returns the last id generated by that sequence. On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method returns the last value generated for such a column, and the table name argument is disregarded. On RDBMS brands that don't support sequences, $tableName and $primaryKey are ignored.
public lastInsertId ( string $tableName = null, string $primaryKey = null ) : string
$tableName string OPTIONAL Name of table.
$primaryKey string OPTIONAL Name of primary key column.
return string
    public function lastInsertId($tableName = null, $primaryKey = null)
    {
        $this->_connect();
        return $this->_connection->lastInsertId();
    }

Usage Example

コード例 #1
0
ファイル: Common.php プロジェクト: jorgenils/zend-framework
 function testInsert()
 {
     $row = array('title' => 'News Item 3', 'subTitle' => 'Sub title 3', 'body' => 'This is body 1', 'date_created' => '2006-05-03 13:13:13');
     $rows_affected = $this->_db->insert(self::TableName, $row);
     $last_insert_id = $this->_db->lastInsertId();
     $this->assertEquals('3', (string) $last_insert_id);
     // correct id has been set
 }
All Usage Examples Of Zend_Db_Adapter_Pdo_Abstract::lastInsertId