get last insert id in magento

In magento you can find last insert id by the following methods .
try below method to find the last insert id in magento.

If you use magento save method than try this to get the last inssert id.

$order->save();
Afetr save method use getId method to get the last insert id in magento 
echo $order->getId(); 


//For custom connection use 
$db_write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sqlQuery = "SELECT * FROM TABLE_NAME ";
$db_write ->query($sqlQuery);
echo $lastInsertId  = $db_write ->fetchOne('SELECT last_insert_id()'); 
                              OR

echo $db_write ->lastInsertId(); // you may also try this.

No comments:

Post a Comment