Magento get last insert id


Magento get last insert id : We often need to get the last inserted id in table. If you are using magento model to save data you can get last inserted id simply using $model->getId(); . Here in this tutorial we are going to explain how you can get the last inserted in table using the magento model.


Magento get last insert id

If you are using magento model you can get last inserted id simply as below. Suppose we are adding data using the model Mage::getModel(‘user/profile’). For this model here is an example –

Magento get last insert id:

     
     $model = Mage::getModel('user/profile');
     $model->setFirstname($firstName); 
     $model->setLastname ($lastName); 
     $model->save();
     $lastInsrtedId = $model->getId();

The above example will give you the last inserted id in the table. $model->getId() gives you last inserted id.


User Ans/Comments

📖 Read More


Advertisements