Retrieving the Primary Key of a Newly Inserted Row using Zend_Db_Table

Written by James Mansson on January 5, 2013 Categories: Databases, Zend Framework 1

Database tables often have an auto-increment field that acts as primary key. Sometimes it is necessary to retrieve this field immediately, for instance when adding a related entry to another table in the database. Fortunately, Zend_Db_Table offers a simple way to access this field, as it is passed back as the return value from the insert function. For instance:

$id = $dbTable->insert($data);

The variable $data is an array containing the values of the record to insert as key-value pairs. It should not include the primary key if the field is auto-increment.

No Comments on Retrieving the Primary Key of a Newly Inserted Row using Zend_Db_Table

Leave a Reply

Your email address will not be published. Required fields are marked *